Amazon S3 PutObject is very slow

Viewed 6382

I am placing files into an S3 storage using the below code. I am finding it is exceedingly slow. The stopwatch indicated 18 seconds+. Any suggests or other experiences?

        // upload the file to S3
        AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKey, secretAccessKey);

        PutObjectRequest request = new PutObjectRequest();

        FileStream fs = new FileStream(sourceFileName, FileMode.Open);

        request.WithInputStream(fs);
        request.WithBucketName(bucketName);
        request.WithKey(keyName);
        Stopwatch stp1 = new Stopwatch();
        stp1.Start();
        client.PutObject(request);
        stp1.Stop();
        fs.Close();

This code is C#. I am using the amazon .net sdk.

The file is only 56K in size and my upload bandwidth is 1.87Mbps.

3 Answers

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!

Related