Trying to launch EC2 instance by copying a code from S3 bucket

+1 vote

I've been trying to launch an ec2 instance which is an Ubuntu AMI using aws-cli and I want to copy my code from an s3 bucket that I created.
I am attaching the command below that I used to spin my EC2 instance:

aws ec2 run-instances --image-id *ubuntu image id* --count 1 --instance-type t2.micro --key-name new_instance --security-group-ids mysecurity --user-data file://aws.txt

My aws.txt file contents :

`#!/bin/bash
sudo apt-get update
sudo apt-get install -y apache2 php7.0 php7.0-curl php7.0-cli
sudo service apache2 start
sudo apt-get install -y python3 python-pip
sudo apt-get update && sudo pip install --upgrade --user awscli
mkdir ~/.aws && cd ~/.aws
touch credentials && touch config
echo "[default]" > credentials
echo "aws_access_key_id = *id here*" >> credentials
echo "aws_secret_access_key = *secret key*" >> credentials
echo "[default]" > config
echo "output = json" >> config
echo "region = ap-south-1" >> config`enter code here`
sudo aws s3 sync s3://*bucket name* var/www/html`



With this,only apache2 and php are getting installed and mkdir isnt working and awscli isn't being installed and because of that I am not able to sync my d3 bucket code with ebs volume, what should I do in this case?
A help will be much appreciated, Thanks in Advance :)
Apr 25, 2018 in AWS by Cloud gunner
• 4,670 points
3,163 views

1 answer to this question.

0 votes
If you observe, it must be giving an error on mkdir ~/.aws && cd ~/.aws line because "~" refers to different location sometime, instead try to use mkdir /home/*username here*/.aws && cd /home/*username here*/.aws
It should work and try and use sudo with the last aws line.
answered Apr 25, 2018 by Flying geek
• 3,280 points

Related Questions In AWS

0 votes
1 answer
0 votes
1 answer

How to copy a folder from S3 to Elastic Beanstalk instance on its creation?

I had encountered similar problem. But i ...READ MORE

answered Aug 24, 2018 in AWS by Archana
• 4,170 points
4,576 views
+3 votes
6 answers

How to move files from amazon ec2 to s3 bucket using command line

Hey, 3 ways you can do this: To ...READ MORE

answered Oct 9, 2018 in AWS by Omkar
• 69,220 points
20,013 views
0 votes
1 answer

Copying existing files in a s3 Bucket to another s3 bucket

Suppose the two buckets in question are ...READ MORE

answered Sep 14, 2018 in AWS by Priyaj
• 58,020 points
15,004 views
0 votes
0 answers
0 votes
0 answers

EC2 Ubuntu 14 default password

I have an EC2 instance running Ubuntu ...READ MORE

Apr 19, 2022 in AWS by Aditya
• 7,680 points
2,141 views
0 votes
1 answer
0 votes
1 answer

Trying to Determine Amazon EC2 instance creation date/time

You can't find as such attribute called ...READ MORE

answered May 29, 2018 in AWS by Flying geek
• 3,280 points
9,765 views
0 votes
1 answer
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