【问题标题】:cloudformation does not seem to run ( or create ) the script in UserDatacloudformation 似乎没有在 UserData 中运行(或创建)脚本
【发布时间】:2015-10-15 13:06:17
【问题描述】:

我的 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/ 中没有创建任何内容。

当我 curl http://169.254.169.254/latest/user-data 时,我确实看到了脚本

【问题讨论】:

    标签: cloud-init amazon-cloudformation


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2020-04-30
      • 2017-07-27
      • 2021-01-16
      • 2023-01-13
      • 1970-01-01
      • 1970-01-01
      • 2019-10-10
      • 2018-07-15
      • 2011-01-16
      相关资源
      最近更新 更多