Custom domain for different stages

I have an app that is using a custom domain with wildcards.
For prod I want to use whatever.mydomain.com
For dev I want to use whatever.mydomain.net

How do I set that up in my serverless.yml file so when I deploy I get the mappings?
I’ve managed to set it up manually in API Gateway

1 Like

Did you ever get a solution to this?

Nope. Tried adding multiple entries but serverless didn’t like that.

I have a setup like this using the https://github.com/amplify-education/serverless-domain-manager plugin:

  1. In my case the DNS names and SSL certificates are not managed via serverless, so this presupposes that they already exist in Route 53 and Certificate Manager

  2. Setup config file with stage specific values:

dev:
  domainName: whatever.mydomain.net
  certificateName: '*.mydomain.net'

prod:
  domainName: whatever.mydomain.com
  certificateName: '*.mydomain.com'
  1. Add custom section to serverless.yml:
custom:
  stage: ${opt:stage, self:provider.stage}
  stageConfig: ${file(<path to config file in step 2>):${self:custom.stage}}
  
  customDomain:
    domainName: ${self:custom.stageConfig.domainName}
    certificateName: ${self:custom.stageConfig.certificateName}
    stage: ${self:custom.stage}
    basePath: <whatever you need this to be>
    createRoute53Record: false

Hope that helps!

3 Likes