1

I’m trying to integrate AWS S3 bucket into my project (a DLL written in C++). I was successful in creating an independent console application based on the AWS SDK provided for C++ that connects to the bucket and uploads a specific file as per requirement. When I used the same code, and added all the dependencies (dlls library and header files) the DLL project compiled with no error. However, the same could not connect to the s3 instance while running. There’s no visible error yet I could figure out that the code could not retrieve any bucket list. I’m sure I missed something but not sure what it is. FYI, for simplicity, I tried to connect to the AWS bucket just once using the: InitAPI(options) { ……….. ……….. } Aws::ShutdownAPI( options)

The simplistic overview of my code:

bool FindTheBucket(const Aws::S3::S3Client& s3Client,
    const Aws::String& bucketName) 
{

    Aws::S3::Model::ListBucketsOutcome outcome = s3Client.ListBuckets();
    
    if (outcome.IsSuccess()) 
    {

        
        Aws::Vector<Aws::S3::Model::Bucket> bucket_list =
            outcome.GetResult().GetBuckets();
        for (Aws::S3::Model::Bucket const& bucket : bucket_list)
        {
            if (bucket.GetName() == bucketName)
            return true;
            
        }
        return false;
    }
    else 
        return false;
}

And the snippet in my main function where the SDK is called....

Aws::SDKOptions options;
    options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Info;
    Aws::InitAPI(options);
    {
        
        Aws::String bucket_name = "testbucket"; // a bucket of the same name exists
        Aws::String region = "us-west-2";
        Aws::Client::ClientConfiguration config;
        config.region = region;
        Aws::S3::S3Client s3_client(config);
    
        if (FindTheBucket(s3_client, bucket_name))
        {
            //do the needful
            std::ofstream myFile(str.c_str());
            myFile.close();
            PutObjectBuffer(bucket_name, str.c_str(),
                layerstr, region);
        }
        else
        {
            //some code…
        }
    }
    Aws::ShutdownAPI(options);
Saby
  • 11
  • 3
  • Could you please share the log output? Usually, when there's no error, it means an authentication error. It's a shame that there's no output about this error :\ – Meir Gabay Mar 13 '21 at 19:19
  • 1
    You are right. My IAM role did not have the S3 Bucket Access. This is sorted. Thank you – Saby Sep 22 '21 at 13:12

0 Answers0