cloudformation似乎没有在UserData中运行(或创建)脚本

时间:2015-07-24 18:44:54

标签: cloud-init amazon-cloudformation

我的cloudformation模板中有这样的东西

    "UserData": {
      "Fn::Base64": {
        "Fn::Join": [
          "",
          [
            "#cloud-config\n",
            "repo_releasever: ",
            {
              "Ref": "LinuxVersion"
            },
            "\n",
            "\n",
            "runcmd:\n",
            " - [curl, -s, -S, -o, /tmp/user_data.txt, 'http://some.s3bucket.amazonaws.com/cfn/some_Script.txt']\n",
            " - [bash, /tmp/user_data.txt]\n",
            " - [mkdir, -p, /root/.aws/\n",
            " - [echo, ' aws_access_key_id = ", { "Ref": "AWSAccessKey" }, " >> /root/.aws/credentials']\n",
            " - [echo, ' aws_secret_access_key' = ",  { "Ref": "AWSSecretAccessKey" },  " >> /root/.aws/credentials']\n"
          ]
        ]
      }
    }
  }
},

CloudFormation配置实例后,如果执行此操作则无。

在/ var / lib / cloud / instance / scripts /.

中没有创建任何内容

当我卷曲http://169.254.169.254/latest/user-data

时,我确实看到了剧本

1 个答案:

答案 0 :(得分:1)

我认为您的UserData的第一行必须是"#!/bin/bash\n",才能使其成为可运行的脚本,因此您的代码的前几行将是:

"UserData": {
  "Fn::Base64": {
    "Fn::Join": [
      "",
      [
        "#!/bin/bash\n",
        "#cloud-config\n",
        "repo_releasever: ",