Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serverless framework 'dev' and 'prod' seperation

I am writing a backend service using the Serverless framework.

What is the best way for separating "Dev" and "Prod" environments?

Let's say I want my dev profile to deploy in a certain region and my prod profile to deploy in another? Is there a way to achieve this in the Serverless framework?

I would like to do something like:

serverless deploy --profile dev (--> use serverless-dev.yml)
serverless deploy --profile prod (--> use serverless-prod.yml)
like image 814
Yoaz Menda Avatar asked May 17 '17 12:05

Yoaz Menda


1 Answers

You can deploy to different environments using stages with the serverless framework. The deploy command has the stage option which you can specify using --stage or -s. The option for region is --region or -r Here's an example:

serverless deploy --stage dev --region us-east-1

This option can also be used to deploy an individual lambda function to a specific environment.

serverless deploy --stage production --region eu-west-1 function --function helloworld

You might also want to use serverless variables to make your environment configuration dynamic. You can access environment variables using the syntax ${env:SOME_VAR}.

There's also a way to make variables stage/region specific using nested variables.

From the docs:

Making your variables stage/region specific:

serverless.env.yml allowed you to have different values for the same variable based on the stage/region you're deploying to. You can achieve the same result by using the nesting functionality of the new variable system. For example, if you have two different ARNs, one for dev stage and the other for prod stage, you can do the following: ${env:${opt:stage}_arn}. This will make sure the correct env var is referenced based on the stage provided as an option. Of course you'll need to export both dev_arn and prod_arn env vars on your local system.

Links to serverless documentation:

Deploy

https://serverless.com/framework/docs/providers/aws/cli-reference/deploy-function/

Workflow recommendations

https://serverless.com/framework/docs/providers/aws/guide/workflow/#using-stages

Serverless Variables

https://serverless.com/framework/docs/providers/aws/guide/variables/

like image 72
user818510 Avatar answered Sep 17 '22 13:09

user818510