Run shell script as EC2 user on Cloud formation User data
0
Hi, I want to run the Shell script n cloudformation userdata section as EC2 user, Could you please guide me how to execute this and whether it is possible or not.
Thanks, Sreenivas.
asked 2 months ago35 views
1 Answers
0
There's a couple different ways you can do it, but this was the one that worked best for me. Add this to your user-data script, minus the nvm stuff of course:
# Install nvm
sudo -u ec2-user -i <<'EOF'
cd /home/ec2-user
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
source /home/ec2-user/.bashrc
nvm install 10.19.0
nvm use 10.19.0
EOF
answered 2 months ago
Relevant questions
Remove user id 1000
Accepted Answerasked 5 months agoRun shell script as EC2 user on Cloud formation User data
asked 2 months agoWhen Delete Stack, Run Script Before Terminating EC2 Instance
asked 3 years agoHow to use EventBridge with Systems Manager Run Command to run shell commands?
Accepted Answerasked 5 months agoHow to retrieve job run id from the script itself in python shell glue job
asked 2 months agoRun shell script as EC2 user on Cloud formation User data
asked 2 months agoDeleting CloudFormation Stacks using a shell script
Accepted Answerasked 2 years agoHow to keep a process running on my EC2 instance via cloud9
asked 3 years agoEC2 User data script for node js using NVM
asked 3 years agoOn Bitnami's Jenkins Run Docker Commands in Jenkins shell ubuntu
Accepted Answerasked 3 years ago