I want to use AWS SDK for .Net to read and write to an S3 bucket, from a web application.
What should be the scope of AmazonS3Client
client?
Looking at ASW sample code they are using a static s3Client
:
private const string bucketName = "*** provide bucket name ***";
private const string keyName = "*** provide a name for the uploaded object ***";
private const string filePath = "*** provide the full path name of the file to upload ***";
// Specify your bucket region (an example region is shown).
private static readonly RegionEndpoint bucketRegion = RegionEndpoint.USWest2;
private static IAmazonS3 s3Client;
Can I create a static
client, for the entire life-time of the application and use the same client for all the web requests?
Or should I create one client per request? i.e. the scope of the object is the web request (as in this example):
using (var client = new AmazonS3Client(RegionEndpoint.USWest2))
{
PutObjectRequest request = new PutObjectRequest()
{
InputStream = imageStream,
BucketName = BucketName,
Key = key
};
client.PutObject(request);
success = true;
}
If I use the later option, then the web application will potentially create multiple connections to the S3 bucket at the same time, because different users are using the website simultaneously).