【问题标题】:Difference between UserData and cfn-helper with CloudFormation AWSCloudFormation AWS 的 UserData 和 cfn-helper 之间的区别
【发布时间】:2015-06-25 15:44:59
【问题描述】:

我开始使用 CloudFormation 进行编排/配置,我发现有两种安装包的方法:

第一种方法是在用户数据部分使用 bash 脚本,例如:

"UserData": {
          "Fn::Base64": {
            "Fn::Join": [
              "\n",
              [
                "#!/bin/bash",
                "apt-get update",
                "apt-get upgrade -y",
                "apt-get install apache2 -y",
                "echo \"<html><body><h1>Welcome</h1>\" > /var/www/index.html",

另一种方法是使用cfn-init:

"UserData"       : { "Fn::Base64" : { "Fn::Join" : ["", [
             "yum update -y aws-cfn-bootstrap\n",

             "# Install the files and packages from the metadata\n",
             "/opt/aws/bin/cfn-init -v ",
             "         --stack ", { "Ref" : "AWS::StackName" },
             "         --resource WebServerInstance ",
             "         --configsets Install ",
             "         --region ", { "Ref" : "AWS::Region" }, "\n"
        ]]}}

是否有任何理由在 UserData 中使用 cfn-init 而不是 bash?

【问题讨论】:

    标签: bash cloud server amazon provisioning


    【解决方案1】:

    实际上,在 UserData 中使用 bash 或 cfn-init 没有区别。 但是要使用 cnf-init 你需要安装包 aws-cfn-bootstrap 就像你已经完成并且还需要定义

    "Resources": {
      "MyInstance": {
        "Type": "AWS::EC2::Instance",
        "Metadata" : {
          "AWS::CloudFormation::Init" : {
            "config" : {
              "packages" : {
                :
              },
              "groups" : {
                :
              },
              "users" : {
                :
              },
              "sources" : {
                :
              },
              "files" : {
                :
              },
              "commands" : {
                :
              },
              "services" : {
                :
              }
            }
          }
        },
        "Properties": {
          :
        }
      }
    }
    

    cfn-init 就像是一种完成工作的干净方式,而不是您需要在 UserData 的 bash 中执行 yum install,尽管您将从这两种方法中获得相同的结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-19
      • 2017-07-02
      • 2017-07-16
      • 1970-01-01
      • 2019-06-13
      • 2022-11-27
      相关资源
      最近更新 更多