1

我的 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时确实看到了脚本

4

1 回答 1

1

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

"UserData": {
  "Fn::Base64": {
    "Fn::Join": [
      "",
      [
        "#!/bin/bash\n",
        "#cloud-config\n",
        "repo_releasever: ",
于 2015-09-02T20:24:31.220 回答