Juan Tarrel
Juan Tarrel

Reputation: 1

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

"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

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

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.

Anybody can help me with that new line characther in the file? enter image description here

Upvotes: 0

Views: 597

Answers (2)

Nick
Nick

Reputation: 1269

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. If you can do it without that, it may work.

Upvotes: 1

Arun Kamalanathan
Arun Kamalanathan

Reputation: 8603

This works for me. Each line could be added as a list item to the "Fn::Join" list.

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

Upvotes: 3

Related Questions