Not able to run script in EC2 AMI instance

0 votes

Hi, I am new in aws cloud please some can help with this script.

UserData:
Fn::Base64: |
#!/bin/bash
sudo su
yum update -y
yum install httpd -y
service httpd start
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
export NVM_DIR="$HOME/.nvm"
&& \. "$NVM_DIR/nvm.sh" # This loads nvm
&& \. "$NVM_DIR/bash_completion"
. /.nvm/nvm.sh
nvm ls-remote
nvm install v12.7.0
nvm use v12.7.0
node -e "console.log('Running Node.js ' + process.version)"
curl -o- -L https://yarnpkg.com/install.sh | bash
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
aws s3 sync s3://reactsearch /var/www/
cd /var/www/
yarn install
yarn run build
Tags:

when I am running vai ssh one by one script then is working fine but when I am using user data script then it's not working. I think 
. /.nvm/nvm.sh not working

Aug 28, 2019 in AWS by Kishore
2,183 views

1 answer to this question.

0 votes
To allow run the 'aws s3 sync' command from the UserData section, you will need to

1. Create an IAM policy to enable reading of objects from the S3 bucket
2. Create a Role to enable the EC2 instance to access the s3 bucket
3. Add the Role to the EC2 instance on Launch creation time
answered Aug 28, 2019 by Randy

Related Questions In AWS

+1 vote
2 answers

How do I run python script on aws EC2 instance(ubuntu)?

I believe that you are using the ...READ MORE

answered Apr 17, 2018 in AWS by Cloud gunner
• 4,670 points
10,275 views
+1 vote
1 answer

How to auto-scale MYSQL database in AWS EC2 instance?

You could always use the Amazon RDS ...READ MORE

answered Aug 24, 2018 in AWS by Archana
• 4,170 points
2,901 views
0 votes
1 answer

How to Pass the VPC ID while creating the Ec2 instance in AWS using Python Boto3

import boto3 ec2 = boto3.resource('ec2') instance = ec2.create_instances( ...READ MORE

answered Jan 29, 2019 in AWS by Priyaj
• 58,100 points
3,508 views
+1 vote
2 answers

How to create an EC2 instance in AWS Console?

Here is a step by step guide ...READ MORE

answered Feb 11, 2019 in AWS by Shubendu
2,142 views
0 votes
1 answer
+1 vote
2 answers
0 votes
1 answer
+2 votes
3 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP