如何在AWS SAM Cloud Formation中使用Route53设置自定义域名



原始问题:如何在SAM云形成中从AWS APIGateway域名中获取RegionalDomainName

编辑:我改变了这个问题,希望这个答案能获得更多的流量,因为它回答了几个问题,而不仅仅是我原来的问题。


当我尝试部署堆栈时,收到以下错误:

resource DomainName does not support attribute type regionalDomainName in Fn::GetAtt

我的yml文件如下所示:

PublicApi:
Type: AWS::Serverless::Api
Properties:
Name: PublicApi
...
EndpointConfiguration: REGIONAL
DomainName:
Type: AWS::ApiGateway::DomainName
Properties:
RegionalCertificateArn: "arn:aws:acm:${Region}:XXXXXXXXXXX:certificate/XXXXXXXXXXXXX"
DomainName: !Sub ${Stage}.${name}
EndpointConfiguration:
Types:
- REGIONAL
myDNSRecord:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId : Z1UJRXOUMOOFQ8
Name: !Sub ${Stage}.${name}
AliasTarget:
HostedZoneId: Z1UJRXOUMOOFQ8 
DNSName: !GetAtt DomainName.regionalDomainName
Type: A
UrlMapping:
Type: AWS::ApiGateway::BasePathMapping
DependsOn:
- PublicApi
Properties:
DomainName: !Ref DomainName
RestApiId: !Ref PublicApi
Stage: !Ref Stage

以下内容来自域名文档:

"RegionalDomainName与此自定义域名的区域终结点关联的域名。您通过添加将自定义域名指向该区域域名的DNS记录来设置此关联。">

我很困惑我需要做什么才能使这个域名成为区域性的。

我在不同的迭代中也得到了以下错误,我认为这应该修复:

"REGIONAL处于活动状态时,无法导入EDGE的证书。">

在这方面的任何帮助都将不胜感激!

我从几个不同的论坛中找到了不同问题的不同解决方案,并最终提出了一个工作模型。我希望这对将来的某个人有所帮助。

PublicApi:
Type: AWS::Serverless::Api
Properties:
Name: PublicApi
StageName: ApiStage
...
EndpointConfiguration: REGIONAL
DomainName:
Type: AWS::ApiGateway::DomainName
Properties:
RegionalCertificateArn: "arn:aws:acm:u${Region}:XXXXXXXX:certificate/XXXXXXXX"
DomainName: stage.example.com
SecurityPolicy: TLS_1_2
EndpointConfiguration:
Types:
- REGIONAL
LambdaDNS:
Type: AWS::Route53::RecordSetGroup
Properties:
HostedZoneName:
Ref: example.com.
RecordSets:
- Name:
Fn::Sub: stage.example.com.
Type: A
AliasTarget:
HostedZoneId: Z1UJRXOUMOOFQ8
DNSName:
Fn::GetAtt:
- DomainName
- RegionalDomainName
UrlMapping:
Type: AWS::ApiGateway::BasePathMapping
DependsOn:
- PublicApi
- PublicApiStage
Properties:
DomainName:
Ref: DomainName
RestApiId:
Ref: PublicApi
Stage: ApiStage

对我来说,关键是BasePathMapping中的DependsOn。

最新更新