jubos / fake-s3

A lightweight server clone of Amazon S3 that simulates most of the commands supported by S3 with minimal dependencies
2.94k stars 355 forks source link

Question: Using with aws-sdk-cpp as a client. #218

Closed mramato closed 6 years ago

mramato commented 6 years ago

I've used fakes3 with the official Node aws-sdk without issue, but I'm struggling to get it to work with the official aws c++ sdk. Here is a complete example that works with real s3 (if I remove the clientConfig section and set the region to us-east-1) but fails with a local fakes3.

I'm running the server with fakes3 --root /C/Data/FakeS3/ -p 4568 and can connect to it using the aws cli with overridden endpoint.

I'm sure it's something I'm doing wrong, so any advice would be a big help. Thanks.

Aws::SDKOptions options;
Aws::InitAPI(options);
{
    Aws::Client::ClientConfiguration clientConfig;
    clientConfig.region = "";
    clientConfig.scheme = Aws::Http::Scheme::HTTP;
    clientConfig.endpointOverride = "http://localhost:4568";
    clientConfig.verifySSL = false;
    clientConfig.maxConnections = 128;

    Aws::S3::S3Client s3_client(clientConfig, false, false);

    Aws::S3::Model::PutObjectRequest object_request;
    object_request.WithBucket("myBucket").WithKey("test.txt");
    auto input_data = Aws::MakeShared<Aws::FStream>("PutObjectInputStream", "C:\\Data\\test.txt", std::ios_base::in | std::ios_base::binary);

    object_request.SetBody(input_data);

    auto put_object_outcome = s3_client.PutObject(object_request);

    if (put_object_outcome.IsSuccess())
    {
        std::cout << "Done!" << std::endl;
    }
    else
    {
        auto error = put_object_outcome.GetError();
        std::cout << "PutObject error: " << error.GetExceptionName() << " " << error.GetMessage() << std::endl;
    }
}
Aws::ShutdownAPI(options);
jubos commented 6 years ago

I am looking into this. I currently get a segfault on the AWS cpp client in trying to reproduce. Is that what you are seeing or just a silent failure?

jubos commented 6 years ago

Looked into this some more and the right way to go is to configure the endpoint like so:

clientConfig.endpointOverride = "localhost:4568";

The aws-sdk documentation for this is pretty sparse. Please reopen the issue if this doesn't resolve it.

mramato commented 6 years ago

Awesome, works like a charm. I should have realized that (since you have to set the scheme separately). Thanks for taking the time to figure it out.