I am new to using serverless framework ,I wanted to create three different environments dev,Qa,prod. How do i create in single serverless.yml file ? The provider is AWS.
You can pass a stage
CLI option that can be interpolated wherever needed in your serverless.yml
file. For example, take the following CLI command:
serverless --stage dev deploy
This can be accessed in serverless.yml
with ${opt:stage}
. I usually include this under provider
:
provider:
stage: ${opt:stage}
Then you can get the value of the stage
option anywhere in serverless.yml
using ${self:provider.stage}
.
When lambdas are deployed, their ARNs are automatically constructed with prefixes of the service
name (as defined by the service
key in serverless.yml
), the stage, and the lambda name, like the following:
arn:aws:lambda:us-east-1:010101010101:function:myservice-dev-mylambdaname
So you can simply run the deploy CLI command for the other two stages/environments you want, and you'll have a set of separate resources for each environment.