Permalink
Browse files

Now auto-setting location contraint for non-classic S3 regions when c…

…alling createBucket.
  • Loading branch information...
1 parent a817adb commit 2f132d618fd4e9727915e49fb2488193ae5068e2 @trevorrowe trevorrowe committed Dec 4, 2012
Showing with 23 additions and 0 deletions.
  1. +14 −0 lib/services/s3.js
  2. +9 −0 test/unit/services/s3.spec.coffee
View
@@ -214,3 +214,17 @@ AWS.S3.Client = inherit(AWS.RESTXMLClient, {
require('./s3.api');
AWS.Client.defineMethods(AWS.S3.Client);
+
+AWS.S3.Client.prototype.createBucket = function createBucket(params, options) {
+ // When creating a bucket *outside* the classic region, the location
+ // constraint must be set for the bucket and it must match the endpoint.
+ // This chunk of code will set the location constraint param based
+ // on the region (when possible), but it will not override a passed-in
+ // location constraint.
+ if (!params) params = {};
+ var hostname = this.endpoint.hostname;
+ if (hostname != 's3.amazonaws.com' && !params.LocationConstraint) {
+ params.LocationConstraint = this.config.region;
+ }
+ return this.makeRequest('createBucket', params, options);
+};
@@ -273,3 +273,12 @@ describe 'AWS.S3.Client', ->
LocationConstraint: 'EU',
RequestId: 'abcxyz',
})
+
+ describe 'createBucket', ->
+ it 'auto-populates the LocationConstraint based on the region', ->
+ loc = null
+ s3 = new AWS.S3.Client(region:'eu-west-1')
+ s3.makeRequest = (op, params) ->
+ loc = params.LocationConstraint
+ s3.createBucket(Bucket:'name')
+ expect(loc).toEqual('eu-west-1')

0 comments on commit 2f132d6

Please sign in to comment.