Home > other >  How to manage different Serverless (with AWS Lambda) environments (ie "dev" and "prod
How to manage different Serverless (with AWS Lambda) environments (ie "dev" and "prod

Time:11-09

I want to create a separate 'dev' AWS Lambda with my Serverless service.

I have deployed my production, 'prod', environment and tried to then deploy a development, 'dev', environment so that I can trial features without affecting customer experience.

In order to deploy the 'dev' environment I have:

  1. Created a new serverless-dev.yml file
  2. Updated the stage and profile fields in my .yml file:
provider:
  name: aws
  runtime: nodejs14.x
  stage: dev
  region: eu-west-2
  profile: dev
  memorySize: 128
  timeout: 30
  1. Also update the resources.Resources.<Logical Id>.Properties.RoleName value, as if I try to use the same role as my 'prod' Lambda, I get this message: clearbit-lambda-role-prod already exists in stack
resources:
  Resources:
    <My Logical ID>:
      Type: AWS::IAM::Role
      Properties:
        Path: /my/cust/path/
        RoleName: clearbit-lambda-role-dev # Change this name
  1. Run command: sls deploy -c serverless-dev.yml

Is this the conventional method to achieve this? I can't find anything in the documentation.

CodePudding user response:

Serverless Framework has support for stages out of the box. You don't need a separate configuration, you can just specify --stage <name-of-stage> when running .e.g sls deploy and it will automatically use that stage. All resources created by the Framework under the hood are including stage in it's names or identifiers. If you are defining some extra resources in resources section, you need to change them, or make sure they include stage in their names. You can get the current stage in configuration with ${sls:stage} and use that to construct names that are e.g. prefixed with stage.

  • Related