【发布时间】:2017-04-08 02:11:29
【问题描述】:
我有一些 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 的实例 ID 使用“文件”部分?
如果我添加 { "Ref" : "AWS::StackId" } 或 { "Ref" : "AWS::Region" },它可以正常工作,但它来自 Pseudo Parameter。
"/var/www/html/index.html" : {
"content" : { "Fn::Join" : ["", [
"<html\n",
"<h1>Apache HTTP Server</h1>\n",
{ "Ref" : "AWS::StackId" },
"</html>\n"
]]},
谢谢!
【问题讨论】:
-
我建议在外部添加文件。即在 S3 上安装它并在 EC2 启动期间拉取它。主要是因为您可以根据需要灵活地向其中添加尽可能多的内容 - 模板不会显得凌乱。然后使用 EC2 启动脚本中的 sed 命令向其注入任何额外数据。
标签: amazon-web-services amazon-ec2 amazon-cloudformation