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 in AWS by Kishore
20 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 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,280 points
2,161 views
0 votes
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,090 points
486 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 in AWS by Priyaj
• 56,900 points
339 views
0 votes
1 answer
0 votes
1 answer
+1 vote
2 answers
+2 votes
3 answers
+1 vote
3 answers

Not able to pass params POST to AWS Lambda from Amazon API Gateway

For this template : application/x-www-form-urlencoded  This line below will ...READ MORE

answered Jun 13, 2018 in AWS by Cloud gunner
• 4,280 points
2,192 views