0% found this document useful (0 votes)
20 views

AWS CLI EC2 Script

The document provides a series of commands (CMDs) to create an EC2 instance on AWS using the command line. It includes steps to generate a key pair, define security groups allowing HTTP/HTTPS access, launch an Ubuntu instance and installing Apache web server to host a basic website.

Uploaded by

Abhishek Mathur
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

AWS CLI EC2 Script

The document provides a series of commands (CMDs) to create an EC2 instance on AWS using the command line. It includes steps to generate a key pair, define security groups allowing HTTP/HTTPS access, launch an Ubuntu instance and installing Apache web server to host a basic website.

Uploaded by

Abhishek Mathur
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CMD-1:

aws ec2 create-key-pair --key-name NameOfTheKeyPair --query 'KeyMaterial' --output text > NameOfTheKeyPair.pem

CMD:-2:
Aws ec2 describe-key-pairs

CMD:-3:
aws ec2 create-key-pair --key-name MyKeyPair --query 'KeyMaterial' --output text | out-file -encoding ascii -filepath
MyKeyPair.pem (optional)

CMD:-4:
aws ec2 describe-security-groups

CMD:-5:
Aws ec2 describe-vpcs

Copy the VPC ID


(Require to create security group)

CMD:-6:

aws ec2 create-security-group --group-name NameOfTheSecuritygroup


--description "NameOfTheSecuritygroup"

CMD:-7:

aws ec2 authorize-security-group-ingress --group-id pastethegroupid --protocol


tcp --port 22 --cidr (paste ip from checkip.amazonaws.com)/32

CMD:-8:

aws ec2 authorize-security-group-ingress --group-id pastethegroupid --protocol


tcp --port 80 --cidr (paste ip from checkip.amazonaws.com)/32

CMD:-9:

aws ec2 authorize-security-group-ingress --group-id pastethegroupid --protocol


tcp --port 443 --cidr (paste ip from checkip.amazonaws.com)/32

********CREATING EC2 MACHINE***********


First copy AMI id from EC2 launch instance and copy the ID from there dashboard

AMI ID:
Security groupid:
Subnet Id: for this go manutally and search VPC and then go to subject make sure you are in Mumbai region only.

CMD:-10:

aws ec2 run-instances --image-id ami-xxxxxxxx --count 1 --instance-type t2.micro --key-name MyKeyPair --security-group-
ids sg-903004f8 --subnet-id subnet-6e7f829e
CMD:11:
Add tags to EC2

aws ec2 create-tags --resources ami-xxxxxxxx --tags Key=Stack,Value=production

You have to create a script to deploy an EC2 Instance and


S3 bucket. using AWS CLI. The details of the Instance are as follows –

o AMI - Ubuntu
o Instance Type - t2.micro
o Security Group Inbound Ports - 22, 80, 443
o Region – Mumbai
o Tag - "Company: Infosys"

All this should be done using a single shell script.


Within the above-mentioned script you need to install Apache Web Server in
the instance. Create an index.html script in the default html location which
should display “Welcome to Infosys Support”.

mxKSX8pA6/QKismC3Vg7wlpeK/FnSRizjjwAJ9oP ----- secret key


AKIAYA66T2MMFXLPREGK ---- ID

You might also like