Skip to content

AWS: Throw an error if ${ssm} fail to populate value, as same as ${cf} and ${s3} #5770

Closed
exoego wants to merge 4 commits into
serverless:masterfrom
exoego:ssm-should-fail
Closed

AWS: Throw an error if ${ssm} fail to populate value, as same as ${cf} and ${s3} #5770
exoego wants to merge 4 commits into
serverless:masterfrom
exoego:ssm-should-fail

Conversation

@exoego

@exoego exoego commented Jan 31, 2019

Copy link
Copy Markdown
Contributor

What did you implement:

Closes #4447
Closes #5757
Closes #5781

How did you implement it:

Before this PR, ${ssm} catches 400 error from AWS SSM, and returns undefined as fulfilled value.
This may cause broken service deployment and user may not notice that.
And, such behavior is incosistent with ${cf} and ${s3}.

After this PR, ${ssm} aborts whenver SSM returns error.
The error can be recovered with the fallback value in the form of ${ssm:/path/param, "fallback"} (already implemented).
So every AWS-specific variable syntaxes has uniform behavior.

How can we verify it:

  1. Install the patched serverless from branch.
npm install -g exoego/serverless#ssm-should-fail`
sls create -t aws-nodejs --path ssm-fail
cd ssm-fail
  1. Update serverless.yml with
service:
  name: aws-nodejs

provider:
  name: aws
  runtime: nodejs8.10

functions:
  hello:
    handler: handler.hello

custom:
  ssmVar: ${ssm:/path/to/service/myParamS}
  1. Run sls deploy and confirm it aborts like
$ sls deploy

  Serverless Error ---------------------------------------
 
  Error getting value for ssm:/path/to/service/myParamS. ParameterNotFound
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com
 
  Your Environment Information -----------------------------
     OS:                     linux
     Node Version:           8.10.0
     Serverless Version:     1.36.3
  1. Add fallback value to serverless.yml like ssmVar: ${ssm:/path/to/service/myParamS, 'fallback'}
  2. Run sls deploy and confirm it complete successfully

Todos:

  • Write tests
  • Write documentation N/A
  • Fix linting errors
  • Make sure code coverage hasn't dropped
  • Provide verification config / commands / resources
  • Enable "Allow edits from maintainers" for this PR
  • Update the messages below

Is this ready for review?: YES
Is it a breaking change?: COULD BE

@eahefnawy eahefnawy self-assigned this Feb 1, 2019
@eahefnawy
eahefnawy self-requested a review February 1, 2019 09:55
@exoego exoego changed the title [WIP] Throw an error if ${ssm} fail to populate value, as same as ${cf} and ${s3} Throw an error if ${ssm} fail to populate value, as same as ${cf} and ${s3} Feb 2, 2019
@exoego exoego changed the title Throw an error if ${ssm} fail to populate value, as same as ${cf} and ${s3} AWS: Throw an error if ${ssm} fail to populate value, as same as ${cf} and ${s3} Feb 17, 2019
@eahefnawy

Copy link
Copy Markdown
Contributor

@exoego I see some updates here, what's the status of this PR?

# Conflicts:
#	lib/classes/Variables.test.js
@exoego

exoego commented Feb 25, 2019

Copy link
Copy Markdown
Contributor Author

This PR is now ready to review.

The change introduced in this PR will provider a broad-based and long-time-awaited behavior, but will be a breaking change, as @pmuens said in #3367 (comment),

I believe fixing this drastically improve DX by preventing deploying broken services, unifying behavior of all variable syntaxes, and providing choices to users.
I also understand serverless framework have strict policy to avoid breaking change as much as possible.

I have a little preference on merging this breaking change to v1, since it is breaking but helps users in essentials. And eventually will open a PR to introduce same behavior to rest of variables (env and other).
But it is OK to postpone the changes to v2.

@pmuens pmuens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@exoego thank you very much for working on this! 👍

I just tested it today and it works fine. Unfortuantely this will intorduce a breaking change which means that we would have to bump to version 2 (as you already mentioned in your comment). Given this I'd say that we should postpone this PR / feature for the v2 release.

Thanks again for taking the time to work on this 🙏

We'll revisit this PR once we're looking into v2!

expect(warnIfNotFoundSpy.callCount).to.equal(0);
})
.finally(() => {
requestStub.restore();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Restores like this should be moved in a beforeEach / afterEach block so that the test suite takes care of the cleanup.

`Error getting value for ssm:${param}.`,
`Parameter ${param} not found.`,
].join(' '))
.then().finally(() => requestStub.restore());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same comment about restore applies here.

@pmuens pmuens closed this Mar 7, 2019
@drissamri

Copy link
Copy Markdown

Is there any workaround to have similar behaviour in v1.38? I don't feel confident if a deploy could go through to production with invalid SSM param setup

@simlu

simlu commented Jul 4, 2019

Copy link
Copy Markdown

I very much agree. This is very unfortunate behavior.

@troyready

troyready commented Apr 22, 2020

Copy link
Copy Markdown

Also would love this to be revisited in 1.0 -- what's the scenario where a deployment should continue if the lookup fails?

Sincerely asking, as I've never encountered this situation without immediately following it up with another deploy.

(EDIT: Obligatory xkcd reference)

@simlu

simlu commented Apr 22, 2020

Copy link
Copy Markdown

@troyready I've encountered a few cases where these should optional. E.g. A logger service has the ability to send to different SaaS. But it only sends to those that have an api key configured.

The fallback would solve that nicely though and also make it explicit.

@bryantbiggs

Copy link
Copy Markdown

@eahefnawy / @medikoo will a v2 branch be opened soon to address some of these changes that have been around for quite some time?

@medikoo

medikoo commented Aug 18, 2020

Copy link
Copy Markdown
Contributor

@bryantbiggs See #3367 it outlines a proposed solution, for which we will welcome a PR.

@exoego
exoego deleted the ssm-should-fail branch January 10, 2022 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

8 participants