在AWS SAM中,REST API网关无法正确处理自定义域名中的"-",这是因为API网关要求自定义域名只能包含字母、数字和点号。
要解决这个问题,可以通过以下步骤:
在AWS控制台上创建一个CloudFormation模板,命名为template.yaml
。
在模板中定义一个AWS::Serverless::Api资源,并指定自定义域名。
Resources:
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
Domain:
DomainName: example.com
CertificateArn: arn:aws:acm:us-west-2:123456789012:certificate/abcdefgh-1234-5678-abcd-123456789012
BasePath: ''
aws cloudformation package --template-file template.yaml --s3-bucket my-bucket --output-template-file packaged.yaml
aws cloudformation deploy --template-file packaged.yaml --stack-name my-stack --capabilities CAPABILITY_IAM
example.com
。这样就可以在API Gateway中正确处理自定义域名中的"-"了。