Issue
I am trying to provide bash command for bootstrapping my ec2 instance during creation time in the following way
aws ec2 run-instances --image-id ami-0000025f7c02a13b2 --count 1 --instance-type t2.micro --user-data '#!/bin/bash\nyum install git -y'
I can spin up the ec2 but I cannot get the bash script to work. In the logs I see the following
/bin/bash\nyum: bad interpreter: No such file or directory
which makes me feel like the string is formatted wrong.
Solution
Try adding a $
in front of your user data string.
aws ec2 run-instances --image-id ami-0000025f7c02a13b2 --count 1 --instance-type t2.micro --user-data $'#!/bin/bash\nyum install git -y'
Answered By - jellycsc