OfficeLinebacker has asked for the wisdom of the Perl Monks concerning the following question:

Greetings, esteemed monks!

I am successfully deleting and creating buckets and populating newly created buckets with files, thanks to Automating upload of files to Amazon S3 Buckets. However I've run into a problem--I want to specify which region the bucked is created in. In Net::Amazon::S3 there is a "geographical constraint" parameter but it seems the only option it takes is 'EU' if you want the bucket to be created in one of the Europe availability regions.

I'd like the ability to create buckets in us-west-2 and other US regions. Is there a way? Perhaps using a different module?

Thanks.
  • Comment on How to specify a Region when creating an AWS S3 bucket?

Replies are listed 'Best First'.
Re: How to specify a Region when creating an AWS S3 bucket?
by marto (Cardinal) on Oct 25, 2013 at 14:09 UTC

    Are you reading the documentation?:

    "Note: This is the legacy interface, please check out Net::Amazon::S3::Client instead."

    Looking at Net::Amazon::S3::Client it shows examples of doing exactly what you want.

      Hi, yes ... but the location_constraint parameter only accepts the values 'US' or 'EU' ... correct? Therefore you'll end up either at the Irland location (EU) or at the US East - N. Virginia location (US). I can't specify other valid AWS locations like eu-central-1 (Frankfurt). See complete list of location constraints: http://docs.aws.amazon.com/general/latest/gr/rande.html Even if I create a bucket in the AWS console - and than using this bucket in my Perl script - I can't create objects in that bucket.
        Isn't it because of the Signature V4? This GitHub PR might fix it.

        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

        Before using location_constraint you must pass the host parameter to the Net::Amazon::S3 constructor. (Note I have never found it necessary to use the param after connecting in this way).

        Here's how I do it:

        $conf = { aws_access_key_id => 'foo', aws_secret_access_key => 'bar', host => 's3-us-west-1.amazonaws.com', }; my $s3_base = Net::Amazon::S3->new( $conf ); my $s3 = Net::Amazon::S3::Client->new( s3 => $s3_base ); my $bucket = $s3->bucket( name => $bucket_name ); ...

        Hope this helps!


        The way forward always starts with a minimal test.
      Dammit. The direction of the answer from the last thread was to use this module.

        Well I don't know what to tell you, other than to suggest that when someone tells you to use Module::X/product X/Service X, take the time to read the documentation and if possible open bugs. It'll save you a lot of time. FWIW this interface looks to be easier to use than the legacy one.