无服务器部署到暂存域名

时间:2021-04-11 19:39:06

标签: amazon-web-services serverless-framework serverless amazon-route53

我正在尝试使用无服务器框架将 API 部署到 AWS 中的域名。我希望能够将阶段作为选项传递并部署到该自定义域名。 例如,阶段 dev 应该使 dev-api.firstcivdivcareers.com

我在 Route53 中有域,为可能的域创建了公共证书,但是当我运行命令时,我收到以下错误。这要么是我尝试在无服务器中使用选项和变量的方式,要么是我未在 AWS 中设置的方式。

仍在学习如何使用无服务器,因此感谢我可以用来调试的任何建议或命令。

错误

$ 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'

1 个答案:

答案 0 :(得分:1)

首先尝试修复 custom 部分中的缩进。 domainNamebasePath 应该在 customDomain 下:

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

baseName 是可选的,所以如果你不需要它,就不要包含它。

相关问题