Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/plugins/aws/deploy/lib/ensure-valid-bucket-exists.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 18 additions & 2 deletions test/unit/lib/plugins/aws/deploy/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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: [{}] },
Expand Down Expand Up @@ -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: [{}] },
Expand Down