Skip to content

Commit bdb5dc6

Browse files
committed
Move to head bucket
When the bucket is in us-east-1, aws sdk v3 returns for getBucketLocation no value as it is null, aws sdk v2 returned an empty string moving to headBucket a region is always returned https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketLocation.html
1 parent 0b7737c commit bdb5dc6

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

lib/plugins/aws/deploy/lib/ensure-valid-bucket-exists.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = {
2727
if (this.serverless.service.provider.deploymentBucket) {
2828
let result;
2929
try {
30-
result = await this.provider.request('S3', 'getBucketLocation', {
30+
result = await this.provider.request('S3', 'headBucket', {
3131
Bucket: this.bucketName,
3232
});
3333
} catch (err) {
@@ -37,9 +37,8 @@ module.exports = {
3737
);
3838
}
3939

40-
if (result.LocationConstraint === '') result.LocationConstraint = 'us-east-1';
41-
if (result.LocationConstraint === 'EU') result.LocationConstraint = 'eu-west-1';
42-
if (result.LocationConstraint !== this.provider.getRegion()) {
40+
if (result.BucketRegion === 'EU') result.BucketRegion = 'eu-west-1';
41+
if (result.BucketRegion !== this.provider.getRegion()) {
4342
throw new ServerlessError(
4443
'Deployment bucket is not in the same region as the lambda function',
4544
'DEPLOYMENT_BUCKET_INVALID_REGION'

test/unit/lib/plugins/aws/deploy/index.test.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ describe('test/unit/lib/plugins/aws/deploy/index.test.js', () => {
118118
LocationConstraint: 'us-east-1',
119119
};
120120
},
121+
headBucket: () => {
122+
return {
123+
BucketRegion: 'us-east-1',
124+
};
125+
},
121126
},
122127
CloudFormation: {
123128
describeStacks: describeStacksStub,
@@ -523,12 +528,16 @@ describe('test/unit/lib/plugins/aws/deploy/index.test.js', () => {
523528
deleteObjects: deleteObjectsStub,
524529
listObjectsV2: { Contents: [] },
525530
upload: s3UploadStub,
526-
headBucket: {},
527531
getBucketLocation: () => {
528532
return {
529533
LocationConstraint: 'us-east-1',
530534
};
531535
},
536+
headBucket: () => {
537+
return {
538+
BucketRegion: 'us-east-1',
539+
};
540+
},
532541
},
533542
CloudFormation: {
534543
describeStacks: describeStacksStub,
@@ -1206,6 +1215,9 @@ describe('test/unit/lib/plugins/aws/deploy/index.test.js', () => {
12061215
getBucketLocation: () => {
12071216
throw new Error();
12081217
},
1218+
headBucket: () => {
1219+
throw new Error();
1220+
},
12091221
},
12101222
CloudFormation: {
12111223
describeStacks: { Stacks: [{}] },
@@ -1242,6 +1254,11 @@ describe('test/unit/lib/plugins/aws/deploy/index.test.js', () => {
12421254
LocationConstraint: 'us-west-1',
12431255
};
12441256
},
1257+
headBucket: () => {
1258+
return {
1259+
BucketRegion: 'us-west-1',
1260+
};
1261+
},
12451262
},
12461263
CloudFormation: {
12471264
describeStacks: { Stacks: [{}] },

0 commit comments

Comments
 (0)