以下是YAML格式的示例云形成文件。我们的想法是使Route53记录依赖于RDS数据库的创建,然后一旦创建它就从RDS数据库的端点获取值。
我在这些参考文档中做了很多讨论,但仍未能正确理解语法。
你可以看到它应该有一个返回值,但我不知道如何获取它并将其用于route53 cName记录名。
resources:
Resources:
uploadBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:custom.uploadBucket}
RDSDatabase:
Type: AWS::RDS::DBInstance
Properties:
Engine : mysql
MasterUsername: ${env:RDS_USERNAME}
MasterUserPassword: ${env:RDS_PASSWORD}
DBInstanceClass : db.t2.micro
AllocatedStorage: '5'
PubliclyAccessible: true
#TODO: The Value of Stage is also available as a TAG automatically which I may use to replace this manually being put here..
Tags:
-
Key: "Name"
Value: ${self:custom.databaseName}
DeletionPolicy: Snapshot
DNSRecordSet:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneName: mydomain.com.
Name: database-${self:custom.stage}.mydomain.com
Type: CNAME
TTL: '300'
ResourceRecords:
- [[Put End Point Here]]
DependsOn: RDSDatabase
我尝试过这样做,但没有运气- ${!Ref RDSDatabase.Endpoint.Address}
An error occurred: DNSRecordSet - Invalid Resource Record: FATAL problem: RRDATANotSingleField (Value contains spaces) encounte
red with '${!Ref RDSDatabase.Endpoint.Address}'.
答案 0 :(得分:3)
找到了答案......
ResourceRecords:
- {"Fn::GetAtt": ["RDSDatabase","Endpoint.Address"]}
我不知道我可以在YAML中使用括号......
答案 1 :(得分:1)
使用!GetAtt
简短形式更具可读性。
ResourceRecords:
- !GetAtt RDSDatabase.Endpoint.Address