amazon-web-services - 您可以在同一cloudformation脚本中将Route53资源记录设置为EC2实例的IP吗?

标签 amazon-web-services amazon-ec2 aws-cloudformation amazon-route53

我有一个 cloudformation 脚本,可以创建 EC2 实例并设置一些警报。我想在同一 cloudformation 中为此实例添加 Route53 记录,但我无法弄清楚要为资源记录字段添加什么内容。 有没有办法为 AWS::Route53::RecordSetGroup 的 ResourceRecord 字段引用新创建的 EC2 实例的 IP 地址?

我已经尝试使用 "ResourceRecords":"EC2Instance" 但这让我“遇到了不受支持的属性类型”。除了创建后手动设置 DNS 条目之外,我不知道如何完成此操作,但我想一步完成,以便自动完成。

这是我所拥有的:

"Resources": {
    "EC2Instance": {
      "Type": "AWS::EC2::Instance",
      "Properties": {"ImageId": {
          "Ref": "AMI"
        },
        "IamInstanceProfile": {
          "Ref": "InstanceProfile"
        },
        "InstanceType": {
          "Ref": "InstanceSize"
        },
        "BlockDeviceMappings": [{
            "DeviceName": "/dev/xvda",
            "Ebs": {
              "Encrypted": true,
              "VolumeSize": 100,
              "DeleteOnTermination": false
            }
          }]
      }
    },
    "DNS": {
      "Type": "AWS::Route53::RecordSetGroup",
      "Properties": {
        "HostedZoneName": {"Ref": "HostedZoneName"},
        "Comment": "Alias Record",
        "ResourceRecords":"EC2Instance",
        "Type": "A",
        "Name": {"Fn::Join" : ["",[{"Ref": "ComponentDNSName"},{"Ref": "HostedZoneName"}]]}
      }
    }
  },

我希望可以通过某种方式找到 EC2 实例新创建的 IP,但我不确定如何找到。我想我必须使用弹性IP,但我仍然不知道如何引用它。感谢您的帮助或建议。

最佳答案

来自AWS::EC2::Instance - AWS CloudFormation :

Fn::GetAtt

The Fn::GetAtt intrinsic function returns a value for a specified attribute of this type. The following are the available attributes and sample return values.

PrivateIp

The private IP address of the specified instance. For example: 10.24.34.0.

所以,它会是这样的:

{ "Fn::GetAtt" : [ "EC2Instance", "PrivateIp" ] }

关于amazon-web-services - 您可以在同一cloudformation脚本中将Route53资源记录设置为EC2实例的IP吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56365898/

相关文章:

laravel - 如何在 AWS Elastic BeanStalk 上配置和运行 crontab?

amazon-web-services - 如何将自签名证书分配给 AWS elastic beanstalk 应用程序

xml - 如何从 ec2 实例中的用户数据编辑 xml 行?

amazon-web-services - 使用 SSL 在 AWS 上托管多个应用程序的最佳方法

amazon-web-services - AWS 无服务器应用程序模型 : Create S3 Event to Lambda

amazon-web-services - AWS lambda 何时支持 python 3.9?

amazon-web-services - 如何为使用计划任务且无服务的 ECS 集群设置自动伸缩?

amazon-web-services - 使用 cloudformation 自动缩放

amazon-web-services - 如何在 CloudFormation 中传递字符串列表作为参数?

aws-cloudformation - AWS Cloudformation 创建 AWS Cloudwatch 事件以触发 AWS Batch