Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having problems accessing bucket that is not using US region with the .Net SDK

I have recently been trying ot write code to add and delete content form an Amazon S3 bucket. I am completely new to Amazon S3 and the AmazonWS .Net SDK.

The bucket region endpoint is http://sqs.eu-west-1.amazonaws.com so I constructed my client like this:

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

If I leave out the AmazonS3Config bit I get this error:

A redirect was returned without a new location. This can be caused by attempting to access buckets with periods in the name in a different region then the client is configured for.

When I put in the AmazonS3Config bit I no longer get that error but I appear to have no access to this bucket at all or any other bucket that I would usually have access to. Any request I send returns null.

I have tested my code with other buckets that are configured to the standard US region and it all works well. The single difference is in the CreateAmazonS3Client method where I set the config with the EU endpoint.

Could anybody give me some guidance on how I should set up my client to work with a bucket in the EU(Ireland) region. I have been searching for a few hours and every tutorial or document I have followed has not worked so far.

like image 973
Ruairi O'Brien Avatar asked Dec 22 '11 18:12

Ruairi O'Brien


People also ask

Can I access S3 bucket from different region?

S3 Multi-Region Access Points provide a single global endpoint to access a data set that spans multiple S3 buckets in different AWS Regions. This allows you to build multi-region applications with the same simple architecture used in a single region, and then to run those applications anywhere in the world.

Are buckets region specific?

Yes the buckets are region specific and you can find the region when you are creating a bucket. By default it will be in your current location of your AWS. You can change it to the region you want. Only the constraint is that you will have to provide a unique bucket name.


1 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);
like image 123
Geoff Appleford Avatar answered Nov 16 '22 01:11

Geoff Appleford