【问题标题】:Cloud Formation Set RDS Endpoint to Route53 CName RecordCloudformation 获取 RDS 端点以路由 53 CName 记录
【发布时间】:2018-06-24 22:39:14
【问题描述】:

以下是 YAML 格式的示例云形成文件。这个想法是让 Route53 记录依赖于 RDS 数据库的创建,然后在创建后从 RDS 数据库的端点获取值。

我在这些参考文档中进行了很多研究,但始终未能正确获取语法。

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-rds-database-instance.html#aws-properties-rds-database-instance-returnvalues

您可以看到它应该有一个返回值,但我不确定如何获取它并将其用于 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}'.

【问题讨论】:

标签: amazon-rds amazon-cloudformation amazon-route53 serverless-framework serverless


【解决方案1】:

找到答案了……

ResourceRecords:
        - {"Fn::GetAtt": ["RDSDatabase","Endpoint.Address"]}

我不知道我可以在 YAML 中使用这样的括号...

【讨论】:

    【解决方案2】:

    使用!GetAtt 短格式更具可读性。

    ResourceRecords:
      - !GetAtt RDSDatabase.Endpoint.Address
    

    【讨论】:

    • 你能告诉我确切的语法错误吗?我目前正在以完全相同的方式使用它。
    • 我认为这是因为我使用的是无服务器,但它会说类似 属性无效,我会尽快尝试重新创建它以获得确切的错误。如果你的方法有效,我肯定更喜欢那个。
    猜你喜欢
    • 2020-08-28
    • 2021-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-07
    • 1970-01-01
    • 1970-01-01
    • 2018-09-28
    • 2014-04-27
    相关资源
    最近更新 更多