我有一些针对AS组的LaunchConfig
"LaunchConfig": {
"Type" : "AWS::AutoScaling::LaunchConfiguration",
"Metadata" : {
"AWS::CloudFormation::Init" : {
"configSets" : {
"InstallAndRun" : [ "Install" ]
},
"Install" : {
"files" : {
"/var/www/html/index.html" : {
"content" : { "Fn::Join" : ["", [
"<html\n",
"<h1>Apache HTTP Server</h1>\n",
"</html>\n"
]]},
"mode" : "000644",
"owner" : "apache",
"group" : "apache"
},
......
可能或最好的方法是为index.html添加一些数据,例如,来自AWS :: EC2 :: Instance的instance-id使用&#34;文件&#34;段?
如果我添加{&#34; Ref&#34; :&#34; AWS :: StackId&#34; }或{&#34;参考&#34; :&#34; AWS :: Region&#34; },它工作正常,但它来自Pseudo Parameter。
"/var/www/html/index.html" : {
"content" : { "Fn::Join" : ["", [
"<html\n",
"<h1>Apache HTTP Server</h1>\n",
{ "Ref" : "AWS::StackId" },
"</html>\n"
]]},
谢谢!
答案 0 :(得分:1)
我不相信它可以直接执行此操作,但您应该能够通过放置文件来完成此操作,然后运行命令来更新它:
(免责声明:我还没有明确地对此进行测试。)
{
"AWS::CloudFormation::Init": {
"configSets": {
"InstallAndRun": [
"Install",
"UpdateIndexHtml"
]
},
"Install": {
"files": {
"/var/www/html/index.html": {
"content": {
"Fn::Join": [
"",
[
"<html\n",
"<h1>Apache HTTP Server</h1>\n",
"---INSTANCE_ID---\n",
"</html>\n"
]
]
},
"mode": "000644",
"owner": "apache",
"group": "apache"
}
}
},
"UpdateIndexHtml": {
"commands": {
"UpdateIndexHtml": {
"command": "sed -i \"s|---INSTANCE_ID---|$(curl -s http://169.254.169.254/latest/meta-data/instance-id)|\" /var/www/html/index.html"
}
}
}
}
}