jhn*_*lvr 6 amazon-web-services aws-cloudformation amazon-route53
当采用类型参数时,AWS::Route53::HostedZone::Id有没有办法获取 HostedZone 名称?
托管区域已经存在,但不是使用 Cloudformation 创建的,因此我无法从另一个模板引用该名称。
使用类型AWS::Route53::HostedZone::Id允许用户从下拉列表中进行选择,但选择的是 ID 而不是名称。
有没有办法从 ID 中获取名称以便创建记录集?
这是我正在使用的模板,注意记录集条目的名称,我们需要托管区域的名称来创建记录集。
AWSTemplateFormatVersion: '2010-09-09'
Description: Route53
Parameters:
HostedZone:
Type: AWS::Route53::HostedZone::Id
Description: The Hosted Zone for the Record Set
RecordSetName:
Type: String
Description: The name of the record set (all lowercase)
Resources:
Route53:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref HostedZone
Comment: DNS name
Name: !Sub ${RecordSetName}.??????
Type: A
TTL: '60'
ResourceRecords:
- 10.1.1.1
Run Code Online (Sandbox Code Playgroud)
考虑到您似乎试图解决的问题(A为您的顶级域添加记录),您实际上并不需要类型的下拉参数选择器AWS::Route53::HostedZone::Id。相反,您可以只使用您的String输入并使用HostedZoneName而不是HostedZoneId如下AWS::Route53::RecordSet所示:
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
DomainName:
Type: String
Description: apex domain name
Resources:
Route53:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneName: !Sub '${DomainName}.'
Comment: DNS name
Name: !Ref DomainName
Type: A
TTL: '60'
ResourceRecords:
- 10.1.1.1
Run Code Online (Sandbox Code Playgroud)
(请注意,您需要在 the 的末尾添加额外的句点.)。DomainNameHostedZoneName
如果您想要一个子域,您可以执行以下操作:
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
DomainName:
Type: String
Description: apex domain name
DomainPrefix:
Type: String
Description: sub domain prefix
Resources:
Route53:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneName: !Sub '${DomainName}.'
Comment: DNS name
Name: !Sub '${DomainPrefix}.${DomainName}'
Type: A
TTL: '60'
ResourceRecords:
- 10.1.1.2
Run Code Online (Sandbox Code Playgroud)
参考Fn::GetAtt,您将在为资源创建 cloudformation 导出时使用这些,而不是像本问题中那样使用资源时。
如果您希望创建包含顶级域名和托管区域 ID 的导出,您可以这样做,这是我更喜欢做的事情,以保持整洁。但是,导出是特定于区域的,因此,如果您跨多个区域进行部署(如果您使用 CloudFront 并希望将 API 部署到 us-east-1 以外的其他区域,则可能会被迫这样做),您将需要在某些区域伪造导出地区。
Fn::GetAtt Fn::GetAtt 内部函数返回此类型的指定属性的值。以下是可用的属性和示例返回值。
有关使用 Fn::GetAtt 内部函数的更多信息,请参阅 Fn::GetAtt。
NameServers 返回特定托管区域的名称服务器集。例如:ns1.example.com。
私有托管区域不支持此属性。
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-route53-hostedzone.html
| 归档时间: |
|
| 查看次数: |
3541 次 |
| 最近记录: |