diff --git a/lib/plugins/aws/deploy/lib/createStack.js b/lib/plugins/aws/deploy/lib/createStack.js index 303b3e441..de10370e8 100644 --- a/lib/plugins/aws/deploy/lib/createStack.js +++ b/lib/plugins/aws/deploy/lib/createStack.js @@ -58,7 +58,12 @@ module.exports = { { StackName: stackName } ) .then((data) => { - if (this.provider.isS3TransferAccelerationEnabled()) { + const shouldCheckStackOutput = + // check stack output only if acceleration is requested + this.provider.isS3TransferAccelerationEnabled() && + // custom deployment bucket won't generate any output (no check) + !this.serverless.service.provider.deploymentBucket; + if (shouldCheckStackOutput) { const isAlreadyAccelerated = !!_.find(data.Stacks[0].Outputs, { OutputKey: 'ServerlessDeploymentBucketAccelerated' }); if (!isAlreadyAccelerated) { @@ -66,7 +71,7 @@ module.exports = { this.provider.disableTransferAccelerationForCurrentDeploy(); } } - BbPromise.resolve('alreadyCreated'); + return BbPromise.resolve('alreadyCreated'); })) .catch((e) => { if (e.message.indexOf('does not exist') > -1) { diff --git a/lib/plugins/aws/deploy/lib/createStack.test.js b/lib/plugins/aws/deploy/lib/createStack.test.js index a75e8e8f6..28d5820e9 100644 --- a/lib/plugins/aws/deploy/lib/createStack.test.js +++ b/lib/plugins/aws/deploy/lib/createStack.test.js @@ -87,6 +87,15 @@ describe('createStack', () => { }); }); + it('should throw error if invalid stack name', () => { + sandbox.stub(awsDeploy, 'create').resolves(); + sandbox.stub(awsDeploy.provider, 'request').resolves(); + awsDeploy.serverless.service.service = 'service-name'.repeat(100); + + return expect(awsDeploy.createStack.bind(awsDeploy)) + .to.throw(awsDeploy.serverless.classes.Error, /not valid/); + }); + it('should set the createLater flag and resolve if deployment bucket is provided', () => { awsDeploy.serverless.service.provider.deploymentBucket = 'serverless'; sandbox.stub(awsDeploy.provider, 'request') @@ -104,7 +113,7 @@ describe('createStack', () => { sandbox.stub(awsDeploy.provider, 'request').rejects(errorMock); - const createStub = sinon + const createStub = sandbox .stub(awsDeploy, 'create').resolves(); return awsDeploy.createStack().catch((e) => { @@ -121,7 +130,7 @@ describe('createStack', () => { sandbox.stub(awsDeploy.provider, 'request').rejects(errorMock); - const createStub = sinon + const createStub = sandbox .stub(awsDeploy, 'create').resolves(); return awsDeploy.createStack().then(() => { @@ -149,5 +158,27 @@ describe('createStack', () => { expect(disableTransferAccelerationStub.called).to.be.equal(true); }); }); + + it('should not disable S3 Transfer Acceleration if custom bucket is used', () => { + const disableTransferAccelerationStub = sandbox + .stub(awsDeploy.provider, + 'disableTransferAccelerationForCurrentDeploy').resolves(); + + const describeStacksOutput = { + Stacks: [ + { + Outputs: [], + }, + ], + }; + sandbox.stub(awsDeploy.provider, 'request').resolves(describeStacksOutput); + + awsDeploy.provider.options['aws-s3-accelerate'] = true; + awsDeploy.serverless.service.provider.deploymentBucket = 'my-custom-bucket'; + + return awsDeploy.createStack().then(() => { + expect(disableTransferAccelerationStub.called).to.be.equal(false); + }); + }); }); });