【发布时间】:2021-10-28 02:22:34
【问题描述】:
我正在开发一个 HTTP API。我需要使用自定义域。我已经拥有该域,并且还从AWS Certificate manager 生成了证书。我的域 DNS 位于 Amazon Route53。
现在我正在尝试将此自定义域附加到我的 HTTP API。我还需要设置基本路径。我正在使用AWS-SAM 模板,下面是我尝试过的。
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
aws-restapi
Sample SAM Template for aws-restapi
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 5
VpcConfig:
SecurityGroupIds:
- sg-041f24sd125s51e8e
SubnetIds:
- subnet-05265b2d
Parameters:
FirebaseProjectId:
Type: String
DomainName:
Type: String
Default: api.example.com
Resources:
AuthGatewayHttpApi:
Type: AWS::Serverless::HttpApi
Properties:
Domain:
DomainName: !Ref DomainName
CertificateArn: arn:aws:acm:us-east-1:xxxx:certificate/xxxxx-xxxx-xxxx-xxxx-xxxxx
Route53:
HostedZoneId: Z096752626aDO8HB8C6
Auth:
Authorizers:
FirebaseAuthorizer:
IdentitySource: $request.header.Authorization
JwtConfiguration:
audience:
- !Ref FirebaseProjectId
issuer: !Sub https://securetoken.google.com/${FirebaseProjectId}
DefaultAuthorizer: FirebaseAuthorizer
AuthFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: aws-restapi/
Handler: source/testfile.lambdaHandler
Runtime: nodejs14.x
Events:
Gateway:
Type: HttpApi
Properties:
ApiId: !Ref AuthGatewayHttpApi
Path: /hello
Method: get
此模板构建良好,但在部署时会引发以下错误。
CREATE_FAILED AWS::Route53::RecordSetGroup RecordSetGroupf015792d8d
[Tried to create resource record set [name='api.example.com.',type='A'] but it already exists]
嗯,这个错误说的是实话,我的域已经到位。我不想再次创建域或证书,我只想在这里使用它们。
我怎样才能完成这项工作?还有我如何设置basePath 这样我就可以像api.example.com/products 一样访问?
【问题讨论】:
-
@petey:不,我很抱歉。它重新创建,我不需要重新创建。至少对于我拥有的嵌套堆栈,它应该开始引用。
标签: amazon-web-services amazon-cloudformation amazon-route53 aws-sam