AWS Classroomnotes 21/May/2022

AWS CLI

  • AWS CLI can be executed from AWS Cloud Shell


  • Installing AWS CLI Refer Here
  • If you instal aws cli then you need to configure credentials. Refer Here to create credentials and configure credentials
  • Refer Here for the ec2 cli docs
  • Lets find the key pairs Refer Here
  • list all the key pairs Refer Here
  • To query the result we can use JMES Path Refer Here
  • Lets see how the jmes path can be used with aws cli
  • For creating instances Refer Here
  • Use the following bash to create an ubuntu 20 image based ec2 instance
#!/bin/bash

# lets find the ec2 key value pairs
keypair=$(aws ec2 describe-key-pairs --query "KeyPairs[0].KeyName")
keypair=${keypair:1:-1}
echo "Selected key pair is $keypair"

# lets find the security group
sg_id=$(aws ec2  describe-security-groups --group-names "openall" --query "SecurityGroups[0].GroupId")
sg_id=${sg_id:1:-1}
echo "Selected security group is ${sg_id}"

# lets find the ami id
ami_id=$(aws ec2 describe-images --filters "Name=owner-id,Values=099720109477" "Name=description, Values='Canonical, Ubuntu, 20.04 LTS, amd64 focal image build on 2022-04-19'" --query "Images[0].ImageId" --output text) 

echo "Selected ami id id ${ami_id}"


instance_size="t2.micro"

aws ec2 run-instances --image-id $ami_id --instance-type $instance_size --key-name $keypair --security-group-ids $sg_id



* To remove the ec2 instance terminate the instance
* Exercise:
* For existing script Refer Here
* Try to create a redhat 8 based ec2 instance from cli
* stop the ec2 instance aws ec2 stop-instances
* start the ec2 instace aws ec2 start-instances
* get the public ip aws ec2 describe-instance --instance-ids <> --query "Reservations[0].Instances[0].PublicIpAddress"
* login into ec2 instance
* install some thing
* logout
* terminate the ec2 instance aws ec2 terminate-instances --instance-id

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%