Skip to content

Add sls:stage and sls:region variables - #6049

Closed
mnapoli wants to merge 1 commit into
serverless:masterfrom
mnapoli:stage-region-aliases
Closed

mnapoli wants to merge 1 commit into
serverless:masterfrom
mnapoli:stage-region-aliases

Conversation

@mnapoli

@mnapoli mnapoli commented Apr 25, 2019 •

Copy link
Copy Markdown
Contributor

What did you implement:

Address #6031 by adding 2 new variables: sls:stage and sls:region.

Those variables are shortcuts to:

${opt:stage, self:provider.stage}
${opt:region, self:provider.region}

How did you implement it:

To be honest I copied existing code, I am not an expert. Feel free to post comments to suggest improvements.

How can we verify it:

I added automated tests but testing with a real serverless.yml would be great (didn't find those in automated tests).

Here is an example:

service: aws-nodejs # NOTE: update this with your service name
provider:
  name: aws
  runtime: nodejs8.10
  stage: customstage
  environment:
    APP_STAGE: ${sls:stage}
functions:
  hello:
    handler: handler.hello

The function could be:

module.exports.hello = async (event) => {
  return { stage: process.env.APP_STAGE };
};

The result of this function should be {"stage":"customstage"}.

Todos:

  • Write tests
  • Write documentation
  • 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?: NO

Those variables are shortcuts to:

```
${opt:stage, self:provider.stage}
${opt:region, self:provider.region}
```

@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.

Thanks for working on this @mnapoli 👍

I like the idea of this implementation. However we can't merge it right now since the fallback to provider.stage will only work if the user has defined the stage in the serverless.yml provider section, making this variable non-deterministic.

I believe we have to wait until #5508 is resolved. Once we made a decision on #5508 we can implement this new variable.

Thanks again for taking the time to work on this 💯

@mnapoli

mnapoli commented Apr 26, 2019

Copy link
Copy Markdown
Contributor Author

👍 I see, thanks for the feedback.

@pmuens pmuens removed this from the 1.42.0 milestone Apr 29, 2019
@pmuens

pmuens commented Apr 30, 2019

Copy link
Copy Markdown
Contributor

@mnapoli thank you for your understanding.

I'll close this PR for now however we'll revisit it once #5508 has been figured out.

Thanks again for working on this 👍

@pmuens pmuens closed this Apr 30, 2019
@mnapoli mnapoli mentioned this pull request Apr 12, 2020
@mnapoli

mnapoli commented Apr 12, 2020

Copy link
Copy Markdown
Contributor Author

Hi @pmuens, would it make sense to reopen this PR now that #5508 has been closed?

@mnapoli

mnapoli commented Apr 13, 2021

Copy link
Copy Markdown
Contributor Author

Follow-up: #9296

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants