我使用以下函数可以获得 PublicDnsName:
{
"Fn::GetAtt": [
"EC2Instance",
"PublicDnsName"
]
}
但是,在我为实例分配静态 IP 后,上述函数有时会返回新的 PublicDnsName,有时会返回旧的 PublicDnsName(我们分配静态 IP 之前的 dns 名称)。
你以前见过这个问题吗?我正在努力寻找原因。请让我知道似乎是什么问题或我应该如何解决它。谢谢。
以下是我的部分 CloudFormation 模板:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Graphite and StatsD",
"Parameters": {
"InstanceType": {
"Type": "String",
"Default": "m1.xlarge"
}
},
"Mappings": {
"RegionMap": {
"us-east-1": {
"AMI": "ami-5ffaa636",
"RecordSetName": "ue1"
},
"us-west-1": {
"AMI": "ami-4ad8ef0f",
"RecordSetName": "uw1"
},
"us-west-2": {
"AMI": "ami-66049d56",
"RecordSetName": "uw2"
},
"eu-west-1": {
"AMI": "ami-861bfbf1",
"RecordSetName": "ew1"
},
"ap-southeast-1": {
"AMI": "ami-42134610",
"RecordSetName": "as1"
},
"ap-southeast-2": {
"AMI": "ami-c98b17f3",
"RecordSetName": "as2"
},
"ap-northeast-1": {
"AMI": "ami-0733a806",
"RecordSetName": "an1"
},
"sa-east-1": {
"AMI": "ami-2bac0a36",
"RecordSetName": "se1"
}
}
},
"Resources": {
"ElasticIP": {
"Type": "AWS::EC2::EIP"
},
"EIPAssociation": {
"Type": "AWS::EC2::EIPAssociation",
"Properties": {
"InstanceId": {
"Ref": "EC2Instance"
},
"EIP": {
"Ref": "ElasticIP"
}
}
},
"DNSRecords": {
"Type": "AWS::Route53::RecordSetGroup",
"Properties": {
"HostedZoneName": "mydomain.com.",
"RecordSets": [
{
"Name": {
"Fn::Join": [
"",
[
"graphite-",
{
"Fn::FindInMap": [
"RegionMap",
{
"Ref": "AWS::Region"
},
"RecordSetName"
]
},
".mydomain.com"
]
]
},
"Type": "CNAME",
"TTL": "300",
"ResourceRecords": [
{
"Fn::GetAtt": [
"EC2Instance",
"PublicDnsName"
]
}
]
}
]
}
},
"EC2Instance": {
"Type": "AWS::EC2::Instance",
"Properties": {
"KeyName": "MyKeyName",
"SecurityGroups": [
"MySecurityGroup"
],
"ImageId": {
"Fn::FindInMap": [
"RegionMap",
{
"Ref": "AWS::Region"
},
"AMI"
]
},
"InstanceType": {
"Ref": "InstanceType"
},
"Tags": [
{
"Key": "Name",
"Value": "graphite-statsd"
}
],
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"",
[
....
VERY LONG SHELL INSTALL SCRIPT
....
]
]
}
}
}
}
}
}