Search code examples
amazon-web-servicesserverless-frameworkserverlessamazon-route53

Serverless Deployment to staging domain name


I am trying to deploy an API to the domain name in AWS using Serverless Framework. I want to be able to pass in the stage as an option and deploy to that custom domain name. For example, stage dev should make dev-api.firstcivdivcareers.com.

I have the domain in Route53, created public certificates for the possible domains, but when I run the command I get the error below. It's either the way I am trying to use options and variables in serverless or something I am not setting up in AWS.

Still learning how to use serverless so any advice or commands I can use to debug is appreciated.

Error:

$ serverless deploy --stage dev
Serverless: Deprecation warning: Starting with next major version, API Gateway naming will be changed from "{stage}-{service}" to "{service}-{stage}".
            Set "provider.apiGateway.shouldStartNameWithService" to "true" to adapt to the new behavior now.
            More Info: https://www.serverless.com/framework/docs/deprecations/#AWS_API_GATEWAY_NAME_STARTING_WITH_SERVICE
Serverless: Bundling with Webpack...
Serverless: No external modules needed
Serverless: Packaging service...
Serverless: Installing dependencies for custom CloudFormation resources...
 
  Error --------------------------------------------------
 
  Error: Unable to fetch information about undefined
      at APIGatewayWrapper.<anonymous> (/Users/kyle/Code/firstcivdivcareers/serverless/JobPostsAPI/node_modules/serverless-domain-manager/dist/src/aws/api-gateway-wrapper.js:109:27)
      at Generator.throw (<anonymous>)
      at rejected (/Users/kyle/Code/firstcivdivcareers/serverless/JobPostsAPI/node_modules/serverless-domain-manager/dist/src/aws/api-gateway-wrapper.js:6:65)
 
     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com
 
  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              12.18.0
     Framework Version:         2.25.2
     Plugin Version:            4.4.3
     SDK Version:               2.3.2
     Components Version:        3.7.0

Serverless.yaml:

service: jobpostsapi
app: firstcivdivcareers
org: kycalica

frameworkVersion: '2'

plugins:
  - serverless-bundle
  - serverless-domain-manager

custom:
  customDomain: ${opt:stage}-api.firstcivdivcareers.com
  domainName: ${opt:stage}-api.firstcivdivcareers.com
  basePath: ''
  stage: ${opt:stage}
  endPointType: regional
  certificateName: '_90e79ed1be1d0eac6e388ed7c2f865d2.firstcivdivcareers.com'
  createRoute53Record: true
  enabled: true

provider:
  name: aws
  runtime: nodejs12.x
  lambdaHashingVersion: 20201221


functions:
  payment:
    handler: handler.payment
    events:
      - http:
          method: post
          path: '/payment'

Solution

  • First try to fix the indentation in the custom section. The domainName and basePath should be under customDomain:

    custom:
      customDomain:
         domainName: ${opt:stage}-api.firstcivdivcareers.com
    

    baseName is optional, so if you don't need it, just don't include it.