1

I'm trying to use the AWS C++ SDK to generate a signed URL for S3, however the Aws::S3::S3Client constructor seems very slow. In the following example:

#include <aws/core/Aws.h>
#include <aws/s3/S3Client.h>
 
int main() {
    Aws::SDKOptions options;
    Aws::InitAPI(options);
    printf("1\n");
    Aws::S3::S3Client client;
    printf("2\n");
    Aws::ShutdownAPI(options);
}

compiled with:

g++ example.cc -laws-cpp-sdk-core -laws-cpp-sdk-s3

there is long delay (at least 5 seconds) between 1 and 2. What is causing this?

The library was built and installed with:

git clone https://github.com/aws/aws-sdk-cpp.git
cd aws-sdk-cpp
cmake . -DCMAKE_BUILD_TYPE=Release -D BUILD_ONLY="s3"
make
make install
wispi
  • 431
  • 3
  • 14

2 Answers2

4

When not running on AWS, set:

AWS_EC2_METADATA_DISABLED=true

to disable the metadata API which is what's causing the delay.

wispi
  • 431
  • 3
  • 14
  • https://github.com/aws/aws-sdk-cpp/issues/1511 this issue explains the "bug" introduced in v1.8x and the workaround above – AdamE Nov 07 '22 at 18:29
2

Not C++, but C#. Your thread was the only one I could find with a title describing my problem. You "inspired" me to go through the AWSOptions's properties.

My newest project is built on .Net 6 and the AWSSDK.S3 Nuget package.

Application startup was blazing fast, but first use / instance creation (through injection) took something like 8 to 10 seconds.

What did the trick for me was setting the DefaultConfigurationMode in Program.cs.

var awsOptions = builder.Configuration.GetAWSOptions();
awsOptions.DefaultConfigurationMode = DefaultConfigurationMode.Standard;

[...]

builder.Services.AddDefaultAWSOptions(awsOptions);
builder.Services.AddAWSService<IAmazonS3>();

I hope this helps someone in the future!

TheMSG
  • 121
  • 4