gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 07:24:52 25 4
gpt4 key购买 nike

我有一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com