Академический Документы
Профессиональный Документы
Культура Документы
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 createkeypair help
aws ec2 createkeypair dryrun <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 createkeypair keyname edurekakeypair
chmod 400 edurekakeypair.pem
Create Security group
aws ec2 createsecuritygroup groupname edurekaSG description "demo class"
aws ec2 authorizesecuritygroupingress groupname edurekaSG protocol tcp port 22 cidr 0.0.0.0/0
Launch EC2 instance
aws ec2 runinstances imageid ami6989a659 count 1 instancetype t1.micro keyname
edurekakeypair securitygroups edurekaSG
Check status
aws ec2 describeinstances
Connect
ssh i edurekakeypair.pem ubuntu@52.27.39.107
Stop instance
aws ec2 stopinstances instanceids i1fc03ac5
aws ec2 describeinstances instanceids i1fc03ac5
Start instance
aws ec2 startinstances instanceids i1fc03ac5
aws ec2 describeinstances instanceids i1fc03ac5
Check Volumes
ec2 describevolumestatus volumeids vol036df2e5
Terminate/cleanup
aws ec2 terminateinstances instanceids i1fc03ac5
aws ec2 describeinstances instanceids i1fc03ac5
ec2 describevolumestatus volumeids vol036df2e5
ec2 deletesecuritygroup groupname edurekaSG
ec2 deletekeypair keyname 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://edurekas3
Create website
vi index.html
aws s3 cp index.html s3://edurekas3/index.html
aws s3 ls s3://edurekas3
Configure website
aws s3 website s3://edurekas3 indexdocument index.html
Check website using your browser
http://edurekas3.s3websiteuswest2.amazonaws.com
Configure bucket policy
vi s3.json (policy generator)
aws s3api putbucketpolicy bucket edurekas3 policy file://s3.json
Check website again
http://edurekas3.s3websiteuswest2.amazonaws.com
Remove bucket
aws s3 rb s3://edurekas3
aws s3 rm s3://edurekas3/index.html
aws s3 rb s3://edurekas3
Verify removal
aws s3 ls
http://edurekas3.s3websiteuswest2.amazonaws.com
RDS: Lifecycle of an MySQL instance
List db instances
aws rds describedbinstances
Create db instance
aws rds createdbinstance dbinstanceidentifier edurekadb allocatedstorage 5 dbinstanceclass
db.t2.micro engine MySQL masterusername edureka masteruserpassword edureka1234$
aws rds describedbinstances dbinstanceidentifier edurekadb
Connect to db instance
mysql h myinstance.123456789012.useast1.rds.amazonaws.com P 3306 u mymasteruser p
Modify db instance
aws rds modifydbinstance dbinstanceidentifier edurekadb backupretentionperiod 0
aws rds modifydbinstance dbinstanceidentifier edurekadb allocatedstorage 6
aws rds describedbinstances dbinstanceidentifier edurekadb
Apply immediately
aws rds modifydbinstance dbinstanceidentifier edurekadb allocatedstorage 6 applyimmediately
Stop
no way to do this
Delete
aws rds deletedbinstance dbinstanceidentifier edurekadb skipfinalsnapshot
Verify
aws rds describedbinstances dbinstanceidentifier edurekadb
aws rds describedbsnapshots
aws rds describedbinstances
VPC: Deploy EC2 in a VPC and connect to it
List VPCs
aws ec2 describevpcs
Create VPC and a subnet
aws ec2 createvpc cidrblock 10.0.0.0/16
aws ec2 createsubnet vpcid vpc9386aff6 cidrblock 10.0.1.0/24
Create internet gateway and attach to VPC
aws ec2 createinternetgateway
aws ec2 attachinternetgateway internetgatewayid igwc1d9baa4 vpcid vpc9386aff6
Create route table and associate to subnet
aws ec2 createroutetable vpcid vpc9386aff6
aws ec2 associateroutetable routetableid rtb9ce8d7f9 subnetid subnetb12914d4
Create route to link internet gateway and route table
aws ec2 createroute routetableid rtb9ce8d7f9 destinationcidr 0.0.0.0/0 gatewayid igwc1d9baa4
Create key pair
aws ec2 createkeypair keyname vpckey
chmod 400 vpckey.pem
Create security group for the VPC and allow port 22 ingress
aws ec2 createsecuritygroup groupname edurkeaVPCSG description "Edureka demo" vpcid
vpc9386aff6
aws ec2 authorizesecuritygroupingress groupid sga4b593c0 protocol tcp port 22 cidr 0.0.0.0/0
Launch an EC2 instance
aws ec2 runinstances imageid ami6989a659 count 1 instancetype t1.micro keyname vpckey
securitygroupids sga4b593c0 subnetid subnetb12914d4 associatepublicipaddress
aws ec2 describeinstancestatus
aws ec2 describeinstances
Connect
ssh i vpckey.pem ubuntu@52.32.184.107
Delete VPC
aws ec2 deletevpc vpcid vpc9386aff6
Delete EC2
aws ec2 describeinstances
aws ec2 terminateinstances instanceid i1ada98de
aws ec2 describeinstancestatus
Delete security group
aws ec2 deletesecuritygroup groupid sga4b593c0
Detach and delete Internet gateway
aws ec2 detachinternetgateway internetgatewayid igwc1d9baa4 vpcid vpc9386aff6
aws ec2 deleteinternetgateway internetgatewayid igwc1d9baa4
Disassociate and delete route table
aws ec2 disassociateroutetable associationid rtbassoce19a8384
aws ec2 deleteroutetable routetableid rtb9ce8d7f9
Delete subnet
aws ec2 deletesubnet subnetid subnetb12914d4
Finally
aws ec2 deletevpc vpcid vpc9386aff6
Verify
aws ec2 describevpcs
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 keypair? 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 bucketpolicy?
● Command for listing contents of a bucket?
RDS ● Command for listing db instances
● Command for creating dbinstance
● Options for createdbinstance
● Command for modifying dbinstance
● 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)