简体   繁体   English

ec2 cloudformation实例的用户数据问题

[英]Problem with user data of ec2 cloudformation instance

I have a problem when i put sh code in the cloudformation template, this json values is on the launchconfig当我将 sh 代码放入 cloudformation 模板时出现问题,此 json 值位于 launchconfig

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

my cloudformation template launch an ec2 instance, after the instance launch is finished i check the configuration here enter image description here我的 cloudformation 模板启动了一个 ec2 实例,实例启动完成后,我在此处检查配置,在此处输入图像描述

enter image description here在此处输入图像描述

the new line character is printed literally and i dont know what is going on, if i check the logs, this is for /var/log/cloud-init-output.log enter image description here换行符是按字面打印的,我不知道发生了什么,如果我检查日志,这是 /var/log/cloud-init-output.log在此处输入图像描述

this configuration is for ecs, before it worked very well but due to this problem I have to figure out how to make the relationship between the cluster and the instance in another way.此配置适用于 ecs,在它运行良好之前,但由于这个问题,我必须弄清楚如何以另一种方式建立集群和实例之间的关系。

Anybody can help me with that new line characther in the file?任何人都可以帮助我处理文件中的新行字符吗? enter image description here在此处输入图像描述

This works for me.这对我有用。 Each line could be added as a list item to the "Fn::Join" list.每一行都可以作为列表项添加到"Fn::Join"列表中。

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

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

A comment here says that they had trouble using one line for user data when they used base64.这里的一条评论说,当他们使用 base64 时,他们在使用一行用户数据时遇到了麻烦。 If you can do it without that, it may work.如果你能做到这一点,它可能会奏效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM