0
votes

I am attempting to write a Cloud Formation Template that will create a launch configuration, ASG, ECS cluster, and register the ec2 instances in the ASG to said cluster.

I have a long userdata.sh file that is used to setup a launch configuration.

By putting this userdata in the yaml file i.e.

   ...
   UserData:
      Fn::Base64: !Sub | 
        #!/bin/bash
        ...

it looks pretty terrible. Also, when i try and plug in the cluster name into the ecs agent ${ECSCluster} with Sub, i get "variable names in Fn::Sub syntax must contain only alphanumeric characters, underscores, periods, and colons". The environment variables in my userdata take on the same form ${ENV_VARIABLE}.

I've tried Passing userdata file to AWS Cloudformation stack but receive "Template format error: YAML not well-formed. "

What is the recommended way for passing in a complex userdata.sh file into a CFT in such a way that you can add the cluster name to the ecs-agent config?

1

1 Answers

1
votes

Error is just stating that it doesn't like the way you reference your variable in Fn::Sub. Instead of $(ECSCluster) it needs to be ${ECSCluster}. See the examples in the docs.