简体   繁体   English

用于自定义Windows AMI的AWS CloudFormation模板未运行cfn-init且未创建相关文件

[英]AWS CloudFormation Template for customized windows AMI not running cfn-init and not creating the related files

Below is my template snippet in which Windows Custom AMI is used to create the server. 下面是我的模板片段,其中使用Windows Custom AMI创建服务器。 Here cfn-init.exe is not getting executed even if I have given it in the userdata block. 即使我在userdata块中指定了cfn-init.exe,也不会执行它。 As a result no files are gettting created in my server. 结果,没有文件在我的服务器中创建。 Please help. 请帮忙。

Thanks in Advance. 提前致谢。

"CMServer":{ 
"Type":"AWS::EC2::Instance",
"Metadata":{ "AWS::CloudFormation::Init":{ 
               "config":{ "files":{ "c:\\cfn
                                    cfn-hup.conf":{ 
                                     "content":{ "Fn::Join":[ "",[ "main\n","stack=",
                                       { "Ref":"AWS::StackName"},"\n","region=",
                                          { "Ref":"AWS::Region"},"\n",
                                            "interval=1"]]}},
                  "c:\\cfn\\hooks.d
                   cfn-auto-reloader.conf":{ "content":{ 
                               "Fn::Join":[ "",[ "cfn-auto-reloader-hook\n",
                                 "triggers=post.update\n",
                            "path=Resources.CMServer.Metadata.AWS::CloudFormation::Init\n",
                              "action=cfn-init.exe -v -s ",{ "Ref":"AWS::StackName"},"                             
                             -r CMServer",
                             " --region ",
                               { 
                                 "Ref":"AWS::Region"},"\n"]]}},
             "C:\\inetpub\\wwwroot\\AWSCM\\Website\\App_Config
            ConnectionStrings.config":{ 
            "content":{ 
             "Fn::Join":[ "",[ 
             "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
             "<connectionStrings>\n",
             "<add name=\"core\" connectionString=\"user id=user;password=******;Data Source=",
        { "Fn::GetAtt": },
          ";Database=CoreDb\"/>\n",
"<add name=\"master\" connectionString=\"user id=user;password=******;Data Source=",
{ "Fn::GetAtt": },
";Database=MasterDb\"/>\n",
"<add name=\"web\" connectionString=\"user id=user;password=******;Data Source=",
{ "Fn::GetAtt": },
";Database=WebdB\"/>\n",
"</connectionStrings>"
]
]
},
"mode" : "000644",
"owner" : "root",
"group" : "root"
}
},
"services":{ 
"windows":{ 
"cfn-hup":{ 
"enabled":"true",
"ensureRunning":"true",
"files":[ 
"c:\\cfn
cfn-hup.conf", "c:\\cfn\\hooks.d
cfn-auto-reloader.conf"
]
}
}
}
}
}
},
"Properties":{ 
"ImageId":{ 
"Fn::FindInMap":[ 
"AWSRegionArch2AMI",
{ 
"Ref":"AWS::Region"
},
"SitecoreCMAMI"
]
},
"SecurityGroupIds":[ 
{ 
"Ref":"CMServerSecurityGroup"
}
],
"SubnetId":{ 
"Ref":"PrivateSubnet1"
},
"InstanceType":{ 
"Ref":"CMInstanceType"
},
"KeyName":{ 
"Ref":"KeyName"
},
"UserData":{ 
"Fn::Base64":{ 
"Fn::Join":[ 
"",
[ 
"<script>\n",
"cfn-init.exe -v -s ",
{ 
"Ref":"AWS::StackName"
},
" -r CMServer",
" --region ",
{ 
"Ref":"AWS::Region"
},
"\n"
"</script>"
]
]
}
},
"Tags":[ `enter code here`
{ 
"Key":"Name",
"Value":"CMServer"
}
]
}
},

Prior creating your customized AMI, you need to enable the 'User Data Execution' from the 'EC2ConfigService Settings' at the instance from which you will create the customized AMI. 在创建自定义AMI之前,需要在创建自定义AMI的实例上从“ EC2ConfigService设置”启用“用户数据执行”。

You can get to EC2ConfigSerice Settings from: "C:\\Program Files\\Amazon\\Ec2ConfigService\\Ec2ConfigServiceSettings.exe" then on the General tab, check 'Enable UserData Execution...' check box. 您可以从以下位置访问EC2ConfigSerice设置:“ C:\\ Program Files \\ Amazon \\ Ec2ConfigService \\ Ec2ConfigServiceSettings.exe”,然后在“常规”选项卡上,选中“启用UserData执行...”复选框。 Only then create the customized AMI. 只有这样才能创建定制的AMI。

A shortcut to the EC2ConfigService Settings is available on windows start view as well. Windows开始视图上也提供了EC2ConfigService设置的快捷方式。

Check that your instance has access to the S3 service (access to the internet). 检查您的实例是否有权访问S3服务(访问互联网)。 In order for the machine to get the UserData it need to be able to connect to the internet. 为了使机器获得UserData,它需要能够连接到Internet。 The Userdata, part of the cloudformation script is kept in the S3 service. Userdata,cloudformation脚本的一部分,保留在S3服务中。 an http call is made to the S3 for getting the UserData. 向S3进行http调用以获取UserData。 According to the script you launch the instance is launched to a private subnet. 根据您启动的脚本,实例将启动到专用子网。 I dont know by the snippet if it's really private but regardless the security groups attached, an instance launched into a VPC (to a subnet - not the default subnet), wont get a public IP. 我不知道该代码段是否真的是私有的,但无论连接的安全组如何,启动到VPC(到子网-不是默认子网)的实例都不会获得公共IP。

If you need to access the internet you'll need to attach a NAT or assign an EIP and update the ACL/security groups if relevant. 如果需要访问Internet,则需要附加NAT或分配EIP并更新ACL /安全组(如果相关)。

I got solved the problem. 我解决了这个问题。 the problem was with template JSON format. 问题在于模板JSON格式。 I tried with single quotes(') instead of double like "\\n", 我尝试使用单引号(')而不是使用双引号(\\ n),

. hence solved. 因此解决了。

thank you for your response. 感谢您的答复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM