Is custom base domain possible yet? (Feb 2017)

Can we make a custom domain yet for our API Gateway functions in any format?

  • https:// random.mycompany.com/ serverless_path
  • https:// random.mycompany.com/ random / serverless_path
  • https:// random.mycompany.com/ fixed / random / serverless_path
  • https:// fixed.mycompany.com/ serverless_path
  • https:// fixed.mycompany.com/ random / serverless_path
  • https:// fixed.mycompany.com/ fixed / random / serverless_path

Spaces added to prevent links in markup.

fixed means something the developer picked.
random means the random code given by default when making a APIG endpoint
serverless_path means the path picked by the developer for the APIG endpoint

5 Likes

All of this can be done, but not directly within serverless. You can put a CloudFront distribution in front of your serverless applications, which itself, can have a Route 53 domain alias. This would give you the subdomain for your API’s that you are looking for as well as the ability to have multiple serverless definitions (API Gateway definitions) within the same domain.

Not sure when/if CloudFront definitions will come to serverless. There is a limitation on being able to supply your own SSL for a CloudFormation defined CloudFront definition, IIRC and there may be other limitations as well making it better to define this manually rather than through configurations. However, that is just a guess.

2 Likes

To follow up this article was written recently to describe how to set it up directly with serverless, in much more detilal.

This plugin has also been created since then.

1 Like

Another option: serverless-domain-manager plugin
I’m using this one in my project and it’s worked well. Handles creation of the Route53 record as well as variable basePath by stage.

Here’s the relevant section from my serverless.yml

plugins:
  - serverless-domain-manager


custom:
  default_stage: jack
  stage: ${opt:stage, self:custom.default_stage}
  customDomain:
    domainName: api.mycorp.com
    certificateName: wildcard.mycorp.com
    basePath: ${self:custom.stage}
    stage: ${self:custom.stage}
    createRoute53Record: true

Hope it helps.