Repository: serverless/serverless (JavaScript)
Date: 2017-01-03 11:15:56+00:00
Task type: Bug Fix

Issue:
No updates are to be performed - exit code 1
# This is a Feature Proposal

## Description

```
Serverless: Updating Stack...
 
  Serverless Error ---------------------------------------
 
     No updates are to be performed.
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
 
  Your Environment Information -----------------------------
     OS:                 linux
     Node Version:       7.2.1
     Serverless Version: 1.4.0
 
error Command failed with exit code 1.
```

I'm not sure how the rest of us feel about this, but I did not expect the `exit code 1`. Do we want to change this? In our case it failed our CI deployment.



Issue discussion:
Same here, an error code 1 in codebuild returns build failed in our code pipeline.  I don't think it should be an error that the stack already exists. Maybe a warning

Solution patch:
diff --git a/lib/plugins/aws/lib/updateStack.js b/lib/plugins/aws/lib/updateStack.js
index 3cb58be8fd2..b7d230778c3 100644
--- a/lib/plugins/aws/lib/updateStack.js
+++ b/lib/plugins/aws/lib/updateStack.js
@@ -4,6 +4,8 @@ const _ = require('lodash');
 const path = require('path');
 const BbPromise = require('bluebird');
 
+const NO_UPDATE_MESSAGE = 'No updates are to be performed.';
+
 module.exports = {
   createFallback() {
     this.createLater = false;
@@ -81,7 +83,13 @@ module.exports = {
       params,
       this.options.stage,
       this.options.region)
-      .then((cfData) => this.monitorStack('update', cfData));
+      .then((cfData) => this.monitorStack('update', cfData))
+      .catch((e) => {
+        if (e.message === NO_UPDATE_MESSAGE) {
+          return;
+        }
+        throw e;
+      });
   },
 
   updateStack() {


Test patch:
diff --git a/lib/plugins/aws/lib/updateStack.test.js b/lib/plugins/aws/lib/updateStack.test.js
index 4ed0e324307..3af2169d197 100644
--- a/lib/plugins/aws/lib/updateStack.test.js
+++ b/lib/plugins/aws/lib/updateStack.test.js
@@ -90,6 +90,11 @@ describe('updateStack', () => {
       sinon.stub(awsDeploy, 'monitorStack').returns(BbPromise.resolve());
     });
 
+    afterEach(() => {
+      updateStackStub.restore();
+      awsDeploy.monitorStack.restore();
+    });
+
     it('should update the stack', () => awsDeploy.update()
       .then(() => {
         expect(updateStackStub.calledOnce).to.be.equal(true);
@@ -110,9 +115,6 @@ describe('updateStack', () => {
           awsDeploy.options.stage,
           awsDeploy.options.region
         )).to.be.equal(true);
-
-        awsDeploy.provider.request.restore();
-        awsDeploy.monitorStack.restore();
       })
     );
 
@@ -135,11 +137,17 @@ describe('updateStack', () => {
           .to.equal(
             '{"Statement":[{"Effect":"Allow","Principal":"*","Action":"Update:*","Resource":"*"}]}'
           );
-
-        awsDeploy.provider.request.restore();
-        awsDeploy.monitorStack.restore();
       });
     });
+
+    it('should success if no changes to stack happened', () => {
+      awsDeploy.monitorStack.restore();
+      sinon.stub(awsDeploy, 'monitorStack').returns(
+        BbPromise.reject(new Error('No updates are to be performed.'))
+      );
+
+      return awsDeploy.update();
+    });
   });
 
   describe('#updateStack()', () => {