Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS: Tell S3 bucket name and how to recover if deployment bucket does not exist #5714

Merged
merged 3 commits into from Jan 28, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/plugins/aws/deploy/lib/checkForChanges.js
Expand Up @@ -41,7 +41,17 @@ module.exports = {
return this.provider.request('S3', return this.provider.request('S3',
'listObjectsV2', 'listObjectsV2',
params params
).then((result) => { ).catch((reason) => {
if (!_.includes(reason.message, 'The specified bucket does not exist')) {
return BbPromise.reject(reason);
}
const stackName = this.provider.naming.getStackName();
return BbPromise.reject(new this.serverless.classes.Error([
`The serverless deployment bucket "${params.Bucket}" does not exist.`,
`Create it manually if you want to reuse the CloudFormation stack "${stackName}",`,
'or delete the stack if it is no longer required.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@exoego what you mean "delete the stack if it is no longer required"? 🤔

Copy link
Contributor Author

@exoego exoego Jan 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, sls remove can not delete the stack of which the deploy bucket is deleted accidentally,
So, if user want to delete the stack which is no longer required, the stack should be manually deleted.

].join(' ')));
}).then((result) => {
if (result && result.Contents && result.Contents.length) { if (result && result.Contents && result.Contents.length) {
const objects = result.Contents; const objects = result.Contents;


Expand Down
17 changes: 17 additions & 0 deletions lib/plugins/aws/deploy/lib/checkForChanges.test.js
Expand Up @@ -135,6 +135,23 @@ describe('checkForChanges', () => {
}); });
}); });


it('should translate error if rejected due to missing bucket', () => {
listObjectsV2Stub
.rejects(new serverless.classes.Error('The specified bucket does not exist'));

return expect(awsDeploy.getMostRecentObjects()).to.be.rejectedWith([
`The serverless deployment bucket "${awsDeploy.bucketName}" does not exist.`,
'Create it manually if you want to reuse the CloudFormation stack "my-service-dev",',
'or delete the stack if it is no longer required.',
].join(' '));
});

it('should throw original error if rejected not due to missing bucket', () => {
listObjectsV2Stub
.rejects(new serverless.classes.Error('Other reason'));
return expect(awsDeploy.getMostRecentObjects()).to.be.rejectedWith('Other reason');
});

it('should resolve if result array is empty', () => { it('should resolve if result array is empty', () => {
const serviceObjects = { const serviceObjects = {
Contents: [], Contents: [],
Expand Down