AWS CLI
- AWS CLI is used to access AWS services from the command line
- For automation AWS CLI is widely used
- Installation: Refer Here for installation
- Configuring AWS CLI
- For authentication it needs access key id and secret access key
- Navigate to IAM and create a user with administrator access
- Create access key and secret key
- execute aws configure
aws configure
- To verify if aws cli is configured or not execute
aws s3 ls
How to work with aws cli
Scenario: Create an ubuntu 22.04 instance in us-east-1 region
- overview

- Any ec2 instance will need
- vpc with subnet (get the id’s or create our own network and subnet)
- security group
- ami id
- size: t2.micro
- CLI
# get vpc id
aws ec2 describe-vpcs
# vpc-cd32bcb0
# get subnet id from az A (us-east-1a)
aws ec2 describe-subnets --filters "Name=availability-zone,Values=us-east-1a"
#subnet-15ede058
# create or use existing security group
aws ec2 describe-security-groups --filters "Name=group-name,Values=openssh"
# sg-0f67708d44b7f6cb1
aws ec2 describe-security-groups --filters "Name=group-name,Values=openhttp"
# sg-0bdd39a6be616d961
# Get key pair name
aws ec2 describe-key-pairs
# id_rsa
# Create an ec2 instance
aws ec2 run-instances \
--instance-type "t2.micro" \
--key-name "id_rsa" \
--security-group-ids "sg-0f67708d44b7f6cb1" "sg-0bdd39a6be616d961" \
--subnet-id "subnet-15ede058" \
--image-id "ami-0fc5d935ebf8bc3bc"
Exercise:
- Create an ec2 instance without public ip address
- Create an ec2 instance with user data to install nginx with public ip
Like this:
Like Loading...