Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up different domains based on stage with serverless-domain-manager plugin?

I am trying to set up different, custom domains in serverless with serverless-domain-manager plugin.

I've followed this tutorial: https://serverless.com/blog/serverless-api-gateway-domain/

but the example doesn't show how to set up more than one custom domain.

In my serverless.yml file I have:

plugins:
  - serverless-domain-manager

custom:
  customDomain:
    basePath: ''
    domainName: MY_DOMAIN_HERE
    stage: dev
    createRoute53Record: true

How can I add another domain? For example, for prod stage?

like image 772
iaforek Avatar asked Oct 26 '17 14:10

iaforek


1 Answers

Even though serverless.yml doesn't support conditional logic, it is possible to simulate conditions.

In serverless.yml add:

custom:
  domain:
    dev: MY_DEV_DOMAIN
    prod: MY_PROD_DOMAIN
  customDomain:
    basePath: ''
    domainName:  ${self:custom.domain.${opt:stage}}
    stage: ${opt:stage}
    createRoute53Record: true

Depending on the sls deploy --stage parameter, either the dev or prod domain will be configured.

More info on conditional logic: https://forum.serverless.com/t/conditional-serverless-yml-based-on-stage/1763

like image 115
iaforek Avatar answered Sep 22 '22 10:09

iaforek