diff --git a/lib/plugins/aws/deploy/lib/ensure-valid-bucket-exists.js b/lib/plugins/aws/deploy/lib/ensure-valid-bucket-exists.js index d41e0d1d0a..525fccdfdc 100644 --- a/lib/plugins/aws/deploy/lib/ensure-valid-bucket-exists.js +++ b/lib/plugins/aws/deploy/lib/ensure-valid-bucket-exists.js @@ -27,7 +27,7 @@ module.exports = { if (this.serverless.service.provider.deploymentBucket) { let result; try { - result = await this.provider.request('S3', 'getBucketLocation', { + result = await this.provider.request('S3', 'headBucket', { Bucket: this.bucketName, }); } catch (err) { @@ -37,9 +37,8 @@ module.exports = { ); } - if (result.LocationConstraint === '') result.LocationConstraint = 'us-east-1'; - if (result.LocationConstraint === 'EU') result.LocationConstraint = 'eu-west-1'; - if (result.LocationConstraint !== this.provider.getRegion()) { + if (result.BucketRegion === 'EU') result.BucketRegion = 'eu-west-1'; + if (result.BucketRegion !== this.provider.getRegion()) { throw new ServerlessError( 'Deployment bucket is not in the same region as the lambda function', 'DEPLOYMENT_BUCKET_INVALID_REGION' diff --git a/package.json b/package.json index 732e70976f..bb82fdab5a 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "ajv": "^8.12.0", "ajv-formats": "^2.1.1", "archiver": "^7.0.1", - "aws-sdk": "^2.1404.0", + "aws-sdk": "^2.1692.0", "bluebird": "^3.7.2", "cachedir": "^2.3.0", "chalk": "^4.1.2", diff --git a/test/unit/lib/plugins/aws/deploy/index.test.js b/test/unit/lib/plugins/aws/deploy/index.test.js index 6263b48b43..a665d172b6 100644 --- a/test/unit/lib/plugins/aws/deploy/index.test.js +++ b/test/unit/lib/plugins/aws/deploy/index.test.js @@ -112,12 +112,16 @@ describe('test/unit/lib/plugins/aws/deploy/index.test.js', () => { deleteObjects: deleteObjectsStub, listObjectsV2: { Contents: [] }, upload: s3UploadStub, - headBucket: {}, getBucketLocation: () => { return { LocationConstraint: 'us-east-1', }; }, + headBucket: () => { + return { + BucketRegion: 'us-east-1', + }; + }, }, CloudFormation: { describeStacks: describeStacksStub, @@ -523,12 +527,16 @@ describe('test/unit/lib/plugins/aws/deploy/index.test.js', () => { deleteObjects: deleteObjectsStub, listObjectsV2: { Contents: [] }, upload: s3UploadStub, - headBucket: {}, getBucketLocation: () => { return { LocationConstraint: 'us-east-1', }; }, + headBucket: () => { + return { + BucketRegion: 'us-east-1', + }; + }, }, CloudFormation: { describeStacks: describeStacksStub, @@ -1206,6 +1214,9 @@ describe('test/unit/lib/plugins/aws/deploy/index.test.js', () => { getBucketLocation: () => { throw new Error(); }, + headBucket: () => { + throw new Error(); + }, }, CloudFormation: { describeStacks: { Stacks: [{}] }, @@ -1242,6 +1253,11 @@ describe('test/unit/lib/plugins/aws/deploy/index.test.js', () => { LocationConstraint: 'us-west-1', }; }, + headBucket: () => { + return { + BucketRegion: 'us-west-1', + }; + }, }, CloudFormation: { describeStacks: { Stacks: [{}] },