我正在尝试创建ec2实例,我希望能够创建一个包含ec2实例公共DNS名称的文件,尽管在下面的代码中我得到了由行引起的循环依赖性错误:
"server_name = \"",{ "Fn::GetAtt" : [ "ECServer", "PublicDnsName" ]},"\"\n","\n"
当我尝试创建ec2时,是否可以在实例部分中获取公共DNS名称?
"ECServer": {
"Type": "AWS::EC2::Instance",
"Metadata" : {
"AWS::CloudFormation::Init" : {
"configSets": {
"Install": ["ECServerConfig"]
},
"ECConfig": {
"files": {
"/tmp/test.txt" : {
"content": { "Fn::Join" : ["", [
"server_name = \"",{ "Fn::GetAtt" : [ "ECServer", "PublicDnsName" ]},"\"\n","\n"
]]},
"mode" : "000644",
"owner": "root",
"group": "root"
}
}
}
}
},
答案 0 :(得分:0)
{{1}}
答案 1 :(得分:0)
您可以使用简单的curl命令获取正在运行的EC2实例的公共IP
1. SSH到该EC2实例。
2.执行以下命令 -
curl http://169.254.169.254/latest/meta-data/public-ipv4