gpt4 book ai didi

amazon-web-services - 如果设置了弹性 IP,CloudFormation PublicDnsName 将返回错误值

转载 作者:行者123 更新时间:2023-12-01 11:41:44 25 4
gpt4 key购买 nike

我使用以下函数可以获得PublicDnsName:

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

但是,在我为实例分配静态 IP 后,上述函数SOMETIMES 返回新的 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
....
]
]
}
}
}
}
}
}

最佳答案

我发现我必须使用 http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-dependson.html以确保首先创建哪些资源。

在本例中,我想确保在调用 DNSRecords 资源之前先创建我的 ElasticIP 资源、EC2Instance 资源和 EIPAssociation 资源。

  {
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Graphite and StatsD",
"Parameters": {
"InstanceType": {
"Type": "String",
"Default": "m1.xlarge"
}
},
"Mappings": {
"RegionMap": {
"us-east-1": {
"AMI": "ami-5ffaa636",
"ShortName": "ue1"
},
"us-west-1": {
"AMI": "ami-4ad8ef0f",
"ShortName": "uw1"
},
"us-west-2": {
"AMI": "ami-66049d56",
"ShortName": "uw2"
},
"eu-west-1": {
"AMI": "ami-861bfbf1",
"ShortName": "ew1"
},
"ap-southeast-1": {
"AMI": "ami-42134610",
"ShortName": "as1"
},
"ap-southeast-2": {
"AMI": "ami-c98b17f3",
"ShortName": "as2"
},
"ap-northeast-1": {
"AMI": "ami-0733a806",
"ShortName": "an1"
},
"sa-east-1": {
"AMI": "ami-2bac0a36",
"ShortName": "se1"
}
}
},
"Resources": {
"ElasticIP": {
"Type": "AWS::EC2::EIP"
},
"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
....
]
]
}
}
},
"DependsOn": [
"ElasticIP"
]
},
"EIPAssociation": {
"Type": "AWS::EC2::EIPAssociation",
"Properties": {
"InstanceId": {
"Ref": "EC2Instance"
},
"EIP": {
"Ref": "ElasticIP"
}
},
"DependsOn": [
"ElasticIP",
"EC2Instance"
]
},
"DNSRecords": {
"Type": "AWS::Route53::RecordSetGroup",
"Properties": {
"HostedZoneName": "mydomain.com.",
"RecordSets": [
{
"Name": {
"Fn::Join": [
"",
[
"graphite-",
{
"Fn::FindInMap": [
"RegionMap",
{
"Ref": "AWS::Region"
},
"ShortName"
]
},
".mydomain.com"
]
]
},
"Type": "CNAME",
"TTL": "300",
"ResourceRecords": [
{
"Fn::GetAtt": [
"EC2Instance",
"PublicDnsName"
]
}
]
}
]
},
"DependsOn": [
"EIPAssociation"
]
}
}
}

关于amazon-web-services - 如果设置了弹性 IP,CloudFormation PublicDnsName 将返回错误值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19803769/

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