========== AWS CLI ========== => AWS provides multiple ways to configure and manage infrastructure => We can use below 4 ways to manage AWS infrastructure 1) AWS Management Web Console (browser) 2) AWS CLI (Command Line Interface) 3) Cloud Formation 4) Terraform =========================== Using the AWS web console =========================== => It is a graphical user interface to connect with various AWS resources, their configuration, modification, etc. => It is very simple to use and does not require knowledge of scripting. ============================ AWS Command Line Interface ============================ => Using AWS CLI we can manage infrastructure in AWS cloud using commands Ex : $ aws s3 ls $ aws ec2 describe-instances ============================ Configuring AWS CLI ============================ 1) Login into AWS account & generate access keys Access Key : AKIAQE43J7YYMPAZMYMT Secret Access key : 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 Note: Not recommended to use root user access keys. 2) Download and Install AWS CLI s/w For windows : https://awscli.amazonaws.com/AWSCLIV2.msi 3) Configure AWS CLI $ aws --version $ aws configure Note: AWS configure command will ask for access key, secret access key, region and output format. ######### CLI Documentation : https://docs.aws.amazon.com/cli/latest/reference/ ########## ================================================ Working with AWS S3 Service using AWS CLI ================================================ => AWS S3 is an object storage service. # list down all buckets available $ aws s3 ls # list down all objects of bucket $ aws s3 ls s3://mybucket --recursive # create bucket in s3 $ aws s3 mb s3://ashokit097978 # copy file into bucket $ aws s3 cp test.txt s3://ashokit097978/test.txt # remove file from bucket $ aws s3 rm s3://ashokit097978/test.txt # remove bucket $ aws s3 rb s3://ashokit097978 ========================== Working with EC2 AWS CLI ========================== # list down all ec2 instances available $ aws ec2 describe-instances # create key-pair in ec2 $ aws ec2 create-key-pair --key-name test --output text > test.pem # Launch EC2 instance $ aws ec2 run-instances --image-id ami-07b69f62c1d38b012 --instance-type t2.micro --key-name test Instance ID : i-03cec5835807f5d8a # stop ec2 instance $ aws ec2 stop-instances --instance-ids i-03cec5835807f5d8a # start ec2 instance $ aws ec2 start-instances --instance-ids i-03cec5835807f5d8a # terminate ec2 instance $ aws ec2 terminate-instances --instance-ids i-03cec5835807f5d8a ================================ Working with AWS RDS using CLI ================================ # creating RDS instance $ aws rds create-db-instance --db-instance-identifier test-mysql-instance --db-instance-class db.t3.micro --engine mysql --master-username admin --master-user-password secret99 --allocated-storage 20 # delete RDS instance $ aws rds delete-db-instance --db-instance-identifier test-mysql-instance --skip-final-snapshot --no-delete-automated-backups ======================================= Installing AWS CLI in Ubunut Linux VM ======================================= $ sudo apt-get install -y python-dev python-pip $ sudo pip install awscli $ aws --version $ aws configure ======================================= Installing AWS CLI in Amazon Linux VM ======================================= curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" unzip awscliv2.zip sudo ./aws/install