简体   繁体   English

是否需要从UserData调用cfn-init?

[英]Does cfn-init need to be called from UserData?

It seems that AWS::CloudFormation::Init has a config section which has files and commands subsections. 似乎AWS::CloudFormation::Init有一个config节,其中包含filescommands子节。 But there is also the Base64-encoded UserData in Properties which calls cfn-init in a sample script that I have: 但是, Properties还有Base64编码的UserData ,它在我具有的示例脚本中调用cfn-init

"Fn::Base64": {
    "Fn::Join": [
        "",
        [
            "<script>\n",
            "cfn-init.exe -v -s ", {
                "Ref": "AWS::StackId"
            },
            " -r MyInstance",
            " --region ", {
                "Ref": "AWS::Region"
            },
            "\n",
..................

My question is - do you need to manually call cfn-init from UserData in order to execute the instructions in AWS::CloudFormation::Init ? 我的问题是-您是否需要从UserData手动调用cfn-init才能执行AWS::CloudFormation::Init的指令? If so, why is that? 如果是这样,那为什么呢? Why not start it automatically so the config section always gets executed if present? 为什么不自动启动它,使config部分始终在存在时执行?

cfn-init.exe is the local component on the EC2 instances that communicates back to the CloudFormation stack to execute the commands inside the AWS::CloudFormation::Init section. cfn-init.exe是EC2实例上的本地组件,可与CloudFormation堆栈通信以执行AWS::CloudFormation::Init部分中的命令。

I don't know, but I believe the reason it doesn't put the actual script inside the User Data is that it doesn't want to modify the User Data in case you have your own scripts in there. 我不知道,但是我相信它没有在用户数据中放入实际脚本的原因是,如果您有自己的脚本,它不想修改用户数据。 Also, the commands to execute could be dynamic from the parameters passed into your CloudFormation script. 另外,要执行的命令可以根据传递给CloudFormation脚本的参数来动态执行。 The cfn-init.exe tool can read these values and make smart choices about how to run the AWS::CloudFormation::Init commands. cfn-init.exe工具可以读取这些值,并就如何运行AWS::CloudFormation::Init命令做出明智的选择。

More information on what cfn-init.exe does here: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-init.html 有关cfn-init.exe功能的更多信息,请cfn-init.exehttp : cfn-init.exe

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

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