100 Days of AWS — Day 22- Introduction to AWS CLI

What is AWS CLI?

The AWS Command Line Interface (AWS CLI) is a unified tool that provides a consistent interface for interacting with all parts of AWS.

The AWS CLI is an open source tool built on top of the AWS SDK for Python (Boto) that provides commands for interacting with AWS services. With minimal configuration, you can start using all of the functionality provided by the AWS Management Console from your favorite terminal program.

# yum -y install python34-pip.noarch
# pip3 install awscli
# pip3 install awscli --upgrade
# aws --versionaws-cli/1.18.147 Python/2.7.18 Linux/5.10.106-102.504.amzn2.x86_64 botocore/1.18.6
# aws configureAWS Access Key ID [None]: XXXXXXXXAWS Secret Access Key [None]: XXXXXXXXDefault region name [None]: us-west-2Default output format [None]: json
# aws <command> <option> --output text
# aws ec2 describe-instances --output text
# aws <command> <option> --output table
# aws ec2 describe-instances --output table

The AWS CLI signs requests on your behalf, and includes a date in the signature. Ensure that your computer’s date and time are set correctly; if not, the date in the signature may not match the date of the request, and AWS rejects the request.

# ls -l ~/.awstotal 8-rw-------. 1 root root  43 May 19 09:18 config-rw-------. 1 root root 116 May 19 09:18 credentials
AWS Command Line Option --> Environment Variables --> CLI configuration file
# aws ec
aws <service(command)> <operation(subcommand)
aws ec2 describe-instances
# echo $SHELL/bin/bash# which aws_completer/bin/aws_completer
# complete -C '/usr/bin/aws_completer' aws
# aws eebs                    ec2-instance-connect   ecs                    eks                    elasticbeanstalk       elastictranscoder      elbv2                  esec2                    ecr                    efs                    elasticache            elastic-inference      elb                    emr                    events
# aws ec2 help
aws ec2 describe-instances help
pip install aws-shell --upgrade --ignore-installed six
# aws-shell
aws ec2 run-instances --generate-cli-skeleton > ec2instance.json
aws ec2 run-instances --cli-input-json file://ec2instance.json
"DryRun": false
# aws ec2 run-instances --image-id ami-0b36cd6786bcfe120 --region us-west-2 --key my-account-key --instance-type t2.micro --output text
# aws ec2 describe-instance-status --region us-west-2 --output text
# aws ec2 terminate-instances --instance-ids i-03dd64a3ec26c34ac
aws ec2 create-key-pair --key-name MyKeyPair --output text
# aws ec2 create-security-group --group-name MySecurityGroup --description "My security group" --vpc-id <vpc-id>
# aws ec2 describe-security-groups --group-names MySecurityGroup
# aws ec2 describe-images --image-ids <ami-id>
aws ec2 run-instances --image-id ami-abc1234 --count 1 --instance-type t2.micro --key-name keypair --subnet-id subnet-abcd1234 --security-group-ids sg-abcd1234
aws ec2 allocate-address
aws ec2 associate-address --instance-id i-abc1234565 --public-ip
o 0 : pending
o 16 : running
o 32 : shutting-down
o 48 : terminated
o 64 : stopping
o 80 : stopped

Creating S3 bucket using AWS Cli

# aws s3 mb s3://100daysofawsmake_bucket: 100daysofaws
# aws s3 ls2022-04-27 03:27:08 100daysofaws
aws s3 mb s3://100daysofaws --region us-west-1
# aws s3 cp index.html s3://100daysofaws
upload: ./index.html to s3://100daysofdevopsbucket/index.html
# aws s3 ls s3://100daysofaws2022-04-27 03:28:56          0 index.html
# aws s3 cp s3://100daysofaws/index.html .download: s3://100daysofaws/index.html to ./index.html
# aws s3 cp s3://mybucket . --recursive
# aws s3 cp . s3://100daysofaws --recursive --exclude "*.jpg"
upload: ./test1.txt to s3://100daysofaws/test1.txt
upload: ./index.html to s3://100daysofaws/index.html
# aws s3 sync . s3://100daysofaws
upload: ./test1.jpg to s3://100daysofaws/test1.jpg
upload: ./test2.txt to s3://100daysofaws/test2.txt
# aws s3 rm s3://100daysofaws/test1.txt
delete: s3://100daysofaws/test1.txt
# aws s3 rm s3://100daysofaws
# aws s3 rm s3://100daysofaws --force



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Prashant Lakhera

Prashant Lakhera

AWS Community Builder, Ex-Redhat, Author, Blogger, YouTuber, RHCA, RHCDS, RHCE, Docker Certified,4XAWS, CCNA, MCP, Certified Jenkins, Terraform Certified, 1XGCP