I am having trouble starting an AWS Ubuntu instance (from the Cloud Formation template) and successfully running the script on startup. This script is executed, but I do not want it to work as root. I want the script to be called as another user or when the script is run for the script to change the user.
Since we are trying to use Cloud Formation, I need to put a script or script link in my template file. The relevant part of my template file is shown below. The script 'myScript.sh' runs, but always as root.
"MyImage" : { "Type" : "AWS::EC2::Instance", "Properties" : { "ImageId" : "xxxxxx", "KeyName" : "xxxxxx", "SecurityGroups" : [ "xxxxxx" ], "UserData" : {"Fn::Base64" : {"Fn::Join" : ["", [ "#include\n", "https://s3-eu-west-1.amazonaws.com/aFolder/myScript.sh \n" ] ] } } } } },
From the URL: http://alestic.com/2009/06/ec2-user-data-scripts it is said that these scripts always run as root. So instead, I decided to change the script to change the user. Below is an example script that does not do what I want. I commented this inline to explain what each step does:
#!/bin/bash whoami > /home/ubuntu/who1.txt
I assume that there is something fundamentally wrong in my script, but I just can't see it! Does anyone have experience with AWS and Cloud Formation, and were you able to run the script as root? I really do not want the script to work as root, since the actions that will be run should not be at the root level.
Thanks Phil
source share