AWS CloudFormation Userdata

amazon-web-services, aws-cloudformation, user-data

Solution

You can do it with perl (extract from one of my Bash script) :

SOURCE_FILE=$1
perl -p -e 's/\"/\\"/g;' "${SOURCE_FILE}"            |  # Escape of "
perl -p -e 's/^(.*)$/"\1\\n",/g;'                    ;  # Add a " at the beginning of each lines + Add a " at the end of each lines \n",
echo '""'
# Add "" as the last line of the file (to match the , from the previous line)

Problem

I have a shell script of about 200 lines. I want to use it to bootstrap an ec2 instance. Is there any tool available for converting shell script into userdata?

Original source