Problems accessing a bucket that does not use the US region with the .Net SDK

I recently tried to write code to add and remove content as an Amazon S3 array. I am completely new to Amazon S3 and AmazonWS.Net SDK.

The endpoint of the bucket area is http://sqs.eu-west-1.amazonaws.com , so I built my client as follows:

_s3Client = AWSClientFactory.CreateAmazonS3Client(accessKey, awsSecretKey, new AmazonS3Config().WithServiceURL("http://sqs.eu-west-1.amazonaws.com")); 

If I do not use the AmazonS3Config bit, I get this error:

Redirects were returned without a new location. This may be caused by an attempt to access buckets with periods in the name in another region that the client is configured for.

When I insert the AmazonS3Config bit, I no longer get this error, but I do not have access to this bucket at all or to any other bucket that I would normally have access to. Any sent request returns null.

I tested my code with other buckets that are configured for the standard US region, and everything works fine. The only difference is the CreateAmazonS3Client method, where I set the configuration with the EU endpoint.

Can someone give me some recommendations on how I should set up my client to work with a bucket in the EU region (Ireland). I searched for several hours, and every textbook or document that I followed has not yet worked.

+6
source share
2 answers

Just use the standard endpoint - s3.amazonaws.com

 AmazonS3Config S3Config = new AmazonS3Config { ServiceURL = "s3.amazonaws.com", CommunicationProtocol = Amazon.S3.Model.Protocol.HTTP }; AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(AWS_Key, AWS_SecretKey, S3Config); PutObjectRequest UploadToS3Request = new PutObjectRequest(); UploadToS3Request.WithFilePath(localPath) .WithBucketName(bucket) .WithKey(key); client.PutObject(UploadToS3Request); 
+15
source

To whom this may still bother.

With the old AWS SDK (version 1), you can simply create an S3 client with no scope or AmazonS3Config . There is no need to provide a service URL; the default value mentioned above is used for you. The only time you really need a region to work with S3, you create a bucket, which is probably rarely a requirement for the application. This works for me, and all the messages that I run for S3 exceed https.

With the new AWS SDK for .Net (version 2 and later), it seems that the scope parameter is required, and in fact AmazonS3Client throws an exception if not set. I tried to get around this limitation with a shared https://s3.amazonaws.com URL and failed because the new SDK does not match 301 redirects from the default endpoint (US-EAST-1, I think).

So, it’s best to specify the region, even the old API, to avoid hacking in the future. If your application makes cross-regional calls both slower (maybe) and more expensive, it's probably best for your code to testify to this.

+4
source

Source: https://habr.com/ru/post/904337/


All Articles