【问题标题】:Problem with user data of ec2 cloudformation instanceec2 cloudformation实例的用户数据问题
【发布时间】:2020-11-25 06:23:55
【问题描述】:

当我将 sh 代码放入 cloudformation 模板时出现问题,此 json 值在启动配置中

"UserData": {
  "Fn::Base64": {
    "Fn::Join": [
      "", [
        "#!/bin/bash \necho ECS_CLUSTER=erp-dev >> /etc/ecs/ecs.config"
      ]
    ]
  }
}

我的 cloudformation 模板启动了一个 ec2 实例,实例启动完成后我在这里检查配置enter image description here

enter image description here

换行符按字面意思打印,我不知道发生了什么,如果我检查日志,这是 /var/log/cloud-init-output.log enter image description here

这个配置是针对ecs的,之前效果很好,但是由于这个问题,我必须弄清楚如何以另一种方式建立集群和实例之间的关系。

任何人都可以帮助我处理文件中的新行字符吗? enter image description here

【问题讨论】:

    标签: bash amazon-web-services amazon-cloudformation devops amazon-ecs


    【解决方案1】:

    这对我有用。每行都可以作为列表项添加到"Fn::Join" 列表中。

    {
      "UserData": {
        "Fn::Base64": {
          "Fn::Join": [
            "", [
              "#!/bin/bash\n",
              "echo ECS_CLUSTER=erp-dev >> /etc/ecs/ecs.config"
            ]
          ]
        }
      }
    }
    

    【讨论】:

    • 你能解释一下什么不起作用。你检查 ecs.config 文件了吗
    【解决方案2】:

    https://serverfault.com/questions/981763/how-do-i-set-user-data-when-using-the-aws-cli-cli-input-json-argument

    这里有一条评论说,当他们使用 base64 时,他们在使用一行用户数据时遇到了问题。如果你能做到这一点,它可能会起作用。

    【讨论】:

      猜你喜欢
      • 2021-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-01
      • 2020-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多