Introduction:
Hello there! If you're new to AWS CLI (Command Line Interface), you're in the right place. In this blog post, I'll walk you through some essential AWS CLI commands to help you get started with managing your AWS resources efficiently. Let's dive in!
What is AWS CLI ?
AWS CLI (Command Line Interface) is a powerful tool that allows you to interact with various AWS services from the command line. It provides a command-line interface for performing operations such as managing EC2 instances, S3 buckets, Lambda functions, and more.
With AWS CLI, you can automate AWS tasks, write scripts, and integrate AWS services into your workflows. It provides a convenient and efficient way to manage your AWS resources without the need for a graphical user interface.
Installation:
To install AWS CLI on your EC2 instance, follow these steps:
Download the AWS CLI package:
curl "
https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip
" -o "
awscliv2.zip
"
Unzip the package:
unzip
awscliv2.zip
Install AWS CLI:
sudo ./aws/install
Configuration:
After installation, configure AWS CLI with your credentials:
aws configure
Enter your AWS Access Key ID and Secret Access Key.
Specify the Default region name (e.g., us-west-2).
Choose the Default output format (json or yaml).
VPC Configuration: Let's create a Virtual Private Cloud (VPC) and configure its components:
Create a VPC:
aws ec2 create-vpc --cidr-block 10.0.0.0/16
Create subnets:
aws ec2 create-subnet --vpc-id vpc-1234567890 --cidr-block 10.0.1.0/24 aws ec2 create-subnet --vpc-id vpc-1234567890 --cidr-block 10.0.2.0/24
Create an internet gateway and attach it to the VPC:
aws ec2 create-internet-gateway aws ec2 attach-internet-gateway --vpc-id vpc-1234567890 --internet-gateway-id igw-1234567890
Create a route table and add a route:
aws ec2 create-route-table --vpc-id vpc-1234567890
aws ec2 create-route --route-table-id rtb-1234567890 --destination-cidr-block 0.0.0.0/0 --gateway-id igw-1234567890
Describe the route tables and subnets:
aws ec2 describe-route-tables --route-table-id rtb-1234567890
aws ec2 describe-subnets --filters "Name=vpcid,Values=vpc-2f09a348" --query 'Subnets[*].{ID:SubnetId,CIDR:CidrBlock}'
Associate the route table with a subnet:
aws ec2 associate-route-table --subnet-id subnet-b46032ec --route-table-id rtb-c1c8faa6
EC2 Instance: Let's work with EC2 instances using AWS CLI:
Describe instance status:
aws ec2 describe-instance-status
Start, stop, and terminate instances:
aws ec2 start-instances --instance-ids i-123456789
aws ec2 stop-instances --instance-ids i-123456789
aws ec2 terminate-instances --instance-ids i-1a2b3c4d
Describe volumes:
aws ec2 describe-volumes
Create a key pair:
aws ec2 create-key-pair --key-name MyKeyPair --query 'KeyMaterial' --output text > MyKeyPair.pem
Create a security group and authorize SSH access:
aws ec2 create-security-group --group-name SSHAccess --description "Security group for SSH access" --vpc-id vpc1234567890
aws ec2 authorize-security-group-ingress --group-id sg-e1fb8c9a --protocol tcp --port 22 --cidr 0.0.0.0/0
Launch an instance:
aws ec2 run-instances --image-id ami-a4827dc9 --count 1 --instance-type t2.micro --key-name MyKeyPair --security-group-ids sg-e1fb8c9a --subnet-id subnet-b46032ec
S3 Operations: Let's explore some AWS S3 operations using CLI:
Create an S3 bucket:
aws s3 mb s3://<bucket-name>
Remove an S3 bucket:
aws s3 rb s3://bucket-name
List S3 buckets:
aws s3 ls
Upload a file to S3:
aws s3 cp C:\Users\test\Desktop\test.png s3://bucketname
IAM Operations: Lastly, let's perform IAM operations using AWS CLI:
Create an IAM user:
aws iam create-user --user-name Employee1
Conclusion: Congratulations! You've learned some essential AWS CLI commands to manage your AWS resources effectively. Remember to explore the AWS CLI documentation for more commands and advanced usage.
Follow me on Linkedin: https://www.linkedin.com/in/ashok-sana
Follow my community:
WhatsApp Group:- https://chat.whatsapp.com/BzX1aruZIH645l29LxvgO3
Telegram:-https://t.me/awsdevopscontent
LinkedIn: https://www.linkedin.com/in/ashok-sana
#AWSCLI #AWSCloud #DevOps #AWSManagement #LinkedInBlog