Вы находитесь на странице: 1из 11

Notes on Module 4: CLI + Assignments 

 
 
Introduction to CLI 
Ec2: Create, stop, start, terminate an EC2 instance 
S3: Create website using S3 bucket 
RDS: Lifecycle of an MySQL instance 
VPC: Deploy EC2 in a VPC and connect to it 
Elastic Beanstalk: Deploy a Rails application 
Review Questions & Assignments 
 

Introduction to CLI 
 
Install and verify 
pip install awscli 
aws configure 
aws ­­version 
 
Verify AWS credentials/configuration 
ls ~/.aws  
vi ~/.aws/config 
format: json/table/text 
choose: table for now/but json is default and best 
 
Get familiar with CLI commands 
aws help 
aws ec2 help 
aws ec2 create­key­pair help 
aws ec2 create­key­pair ­­dry­run <options> 
 
AWS CLI reference 
http://docs.aws.amazon.com/cli/latest/reference/ 

   
 

IMPORTANT: IN COMMANDS BELOW COMPONENT IDS 
(e.g. EC2 instance ids) ARE JUST EXAMPLES. MAKE 
SURE YOU USE YOUR OWN INSTANCE IDS. 

   
Ec2: Create, stop, start, terminate an EC2 instance 
 
Create Key pair 
aws ec2 create­key­pair ­­key­name edureka­key­pair 
chmod 400 edureka­key­pair.pem 
 
Create Security group 
aws ec2 create­security­group ­­group­name edurekaSG ­­description "demo class" 
aws ec2 authorize­security­group­ingress ­­group­name edurekaSG ­­protocol tcp ­­port 22 ­­cidr 0.0.0.0/0 
 
Launch EC2 instance 
aws ec2 run­instances ­­image­id ami­6989a659 ­­count 1 ­­instance­type t1.micro ­­key­name 
edureka­key­pair ­­security­groups edurekaSG 
 
Check status 
aws ec2 describe­instances 
 
Connect 
ssh ­i edureka­key­pair.pem ubuntu@52.27.39.107 
 
Stop instance 
aws ec2 stop­instances ­­instance­ids i­1fc03ac5 
aws ec2 describe­instances ­­instance­ids i­1fc03ac5 
 
Start instance 
aws ec2 start­instances ­­instance­ids i­1fc03ac5 
aws ec2 describe­instances ­­instance­ids i­1fc03ac5 
 
Check Volumes 
ec2 describe­volume­status ­­volume­ids vol­036df2e5 
 
Terminate/cleanup 
aws ec2 terminate­instances ­­instance­ids i­1fc03ac5 
aws ec2 describe­instances ­­instance­ids i­1fc03ac5 
ec2 describe­volume­status ­­volume­ids vol­036df2e5 
ec2 delete­security­group ­­group­name edurekaSG 
ec2 delete­key­pair ­­key­name edureka 
 
   
S3: Create website using S3 bucket 
 
List buckets already existing 
aws s3 ls 
 
Create bucket 
aws s3 mb s3://edureka 
aws s3 mb s3://edureka­s3 
 
Create website 
vi index.html 
aws s3 cp index.html s3://edureka­s3/index.html 
aws s3 ls s3://edureka­s3 
 
Configure website 
aws s3 website s3://edureka­s3 ­­index­document index.html 
 
Check website using your browser 
http://edureka­s3.s3­website­us­west­2.amazonaws.com 
 
Configure bucket policy 
vi s3.json (policy generator) 
aws s3api put­bucket­policy ­­bucket edureka­s3 ­­policy file://s3.json 
 
Check website again 
http://edureka­s3.s3­website­us­west­2.amazonaws.com 
 
Remove bucket 
aws s3 rb s3://edureka­s3 
aws s3 rm s3://edureka­s3/index.html 
aws s3 rb s3://edureka­s3 
 
Verify removal 
aws s3 ls 
http://edureka­s3.s3­website­us­west­2.amazonaws.com 
 
 
 
 
   
RDS: Lifecycle of an MySQL instance 
 
List db instances 
aws rds describe­db­instances 
 
Create db instance 
aws rds create­db­instance ­­db­instance­identifier edurekadb ­­allocated­storage 5 ­­db­instance­class 
db.t2.micro ­­engine MySQL ­­master­username edureka ­­master­user­password edureka1234$ 
aws rds describe­db­instances ­­db­instance­identifier edurekadb 
 
Connect to db instance 
mysql ­h myinstance.123456789012.us­east­1.rds.amazonaws.com ­P 3306 ­u mymasteruser ­p 
 
Modify db instance 
aws rds modify­db­instance ­­db­instance­identifier edurekadb ­­backup­retention­period 0 
aws rds modify­db­instance ­­db­instance­identifier edurekadb ­­allocated­storage 6 
aws rds describe­db­instances ­­db­instance­identifier edurekadb 
 
Apply immediately 
aws rds modify­db­instance ­­db­instance­identifier edurekadb ­­allocated­storage 6 ­­apply­immediately 
 
Stop 
no way to do this 
 
Delete 
aws rds delete­db­instance ­­db­instance­identifier edurekadb ­­skip­final­snapshot 
 
Verify 
aws rds describe­db­instances ­­db­instance­identifier edurekadb 
aws rds describe­db­snapshots 
aws rds describe­db­instances 
 
 
   
VPC: Deploy EC2 in a VPC and connect to it 
 
List VPCs 
aws ec2 describe­vpcs 
 
Create VPC and a subnet 
aws ec2 create­vpc ­­cidr­block 10.0.0.0/16 
aws ec2 create­subnet ­­vpc­id vpc­9386aff6 ­­cidr­block 10.0.1.0/24 
 
Create internet gateway and attach to VPC 
aws ec2 create­internet­gateway 
aws ec2 attach­internet­gateway ­­internet­gateway­id igw­c1d9baa4 ­­vpc­id vpc­9386aff6 
 
Create route table and associate to subnet 
aws ec2 create­route­table ­­vpc­id vpc­9386aff6 
aws ec2 associate­route­table ­­route­table­id rtb­9ce8d7f9 ­­subnet­id subnet­b12914d4 
 
Create route to link internet gateway and route table 
aws ec2 create­route ­­route­table­id rtb­9ce8d7f9 ­­destination­cidr 0.0.0.0/0 ­­gateway­id igw­c1d9baa4 
 
Create key pair 
aws ec2 create­key­pair ­­key­name vpckey 
chmod 400 vpckey.pem 
 
Create security group for the VPC and allow port 22 ingress 
aws ec2 create­security­group ­­group­name edurkeaVPCSG ­­description "Edureka demo" ­­vpc­id 
vpc­9386aff6 
aws ec2 authorize­security­group­ingress ­­group­id sg­a4b593c0 ­­protocol tcp ­­port 22 ­­cidr 0.0.0.0/0 
 
Launch an EC2 instance 
aws ec2 run­instances ­­image­id ami­6989a659 ­­count 1 ­­instance­type t1.micro ­­key­name vpckey 
­­security­group­ids sg­a4b593c0 ­­subnet­id subnet­b12914d4 ­­associate­public­ip­address 
 
aws ec2 describe­instance­status 
aws ec2 describe­instances 
 
Connect  
ssh ­i vpckey.pem ubuntu@52.32.184.107 
 
 
Delete VPC 
aws ec2 delete­vpc ­­vpc­id vpc­9386aff6 
 
Delete EC2 
aws ec2 describe­instances 
aws ec2 terminate­instances ­­instance­id i­1ada98de 
aws ec2 describe­instance­status 
 
Delete security group 
aws ec2 delete­security­group ­­group­id sg­a4b593c0 
 
Detach and delete Internet gateway 
aws ec2 detach­internet­gateway ­­internet­gateway­id igw­c1d9baa4 ­­vpc­id vpc­9386aff6 
aws ec2 delete­internet­gateway ­­internet­gateway­id igw­c1d9baa4 
 
Disassociate and delete route table 
aws ec2 disassociate­route­table ­­association­id rtbassoc­e19a8384 
aws ec2 delete­route­table ­­route­table­id rtb­9ce8d7f9 
 
Delete subnet 
aws ec2 delete­subnet ­­subnet­id subnet­b12914d4 
 
Finally 
aws ec2 delete­vpc ­­vpc­id vpc­9386aff6 
 
Verify 
aws ec2 describe­vpcs 
 
 
   
Elastic Beanstalk: Deploy a Rails application 
 
sudo pip install awsebcli 
sudo pip install ­­upgrade setuptools 
pip install ­­upgrade awsebcli 
 
Create a Rails App 
rails new demo 
cd demo 
git init 
git add ­A 
git commit 
 
Create welcome page 
rails g controller welcome index 
vi config/routes.rb 
git commit 
 
Create Rails secret key for production environment 
rbenv exec rake secret 
 
Configure EB 
eb init ­­interactive 
 
Create environment 
eb create 
 
View logs to determine errors 
eb logs 
 
Verify deployment 
eb open 
 
Configure environment 
eb setenv SECRET_KEY_BASE= 
 
Check status/logs for more information 
eb status 
eb events 
eb logs ­­all 
 
Make changes to Rails app 
vi app/views/welcome/index.html.erb 
git commit ­a 
 
Deploy changes 
eb deploy 
 
Verify deployment 
eb open 
 
Terminate environment 
eb terminate 
 
 
 
   
Review Questions & Assignments 
 
Service  Questions 

AWS CLI  ● What tools do you use to install AWS CLI? 
● What command to configure the CLI? 
● Where are configurations stored? 
● What command can we use to help on the AWS CLI 
● What other resources are available for the CLI? 

AWS CLI vs web  ● Under what circumstances is the CLI better than web console? 
console 

EC2  ● What is the CLI command to create a key­pair? what options? 
● What is the command list instances? 
● What is the command to launch new instances? 
● What is the command to create new security group rule 
(ingress)? 
 

S3  ● Command for listing buckets? 
● Command for creating new bucket? 
● Command for creating bucket­policy? 
● Command for listing contents of a bucket? 

RDS  ● Command for listing db instances 
● Command for creating db­instance 
● Options for create­db­instance 
● Command for modifying db­instance 
● How to apply immediately 

VPC  ● Command for creating VPC 
● Command for creating subnet 
● Command for creating route table 
● Command for listing VPCs 

EB  ● What is an application? 
● What is an environment? 
● What CL tool do we use for EB? 
● Command for configuring environment? 
● Command for creating an environment? 
● Command for listing events? 
● How do we get deployment logs? 
● Command to deploy git changes? 
● Command to open url? 

Assignments 
1. Do following using the web console: 
● EC2: Create, connect and terminate an EC2 instance 
● S3: Create bucket, deploy a simple website. Test if it works. 
● CloudFront: Create distribution pointing to your S3 bucket. Test if it works. 
● RDS: Create, connect and terminate an RDS instance 
● VPC: Create a VPC with scenario 2 (Public, Private subnets), create an EC2 instance 
in the public subnet and an RDS instance in the private subnet. Connect to EC2, RDS 
instances. Terminate all components 
● EB: Using EB, deploy an app using your favorite platform (e.g. PHP or Java), including 
an RDS instance. Test if it works. Make changes to the application and deploy 
changes as well. 
2. Repeat above using the CLI toolkit or your favorite SDK (e.g. Java SDK) 
 
 
 

Вам также может понравиться