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.

Fn::Base64: |
sudo su
yum update -y
yum install httpd -y
service httpd start
curl -o- | bash
export NVM_DIR="$HOME/.nvm"
&& \. "$NVM_DIR/" # This loads nvm
&& \. "$NVM_DIR/bash_completion"
. /.nvm/
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 | 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

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/ not working

Aug 28, 2019 in AWS by Kishore

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,650 points
+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,150 points
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,140 points
+1 vote
2 answers
0 votes
1 answer
+1 vote
2 answers
0 votes
1 answer
+2 votes
3 answers