Title: A Beginner's Guide to AWS CLI Commands

Title: A Beginner's Guide to AWS CLI Commands

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:

  1. Download the AWS CLI package:

    curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"

  2. Unzip the package:

    unzip awscliv2.zip

  3. 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:

  1. Create a VPC:

    aws ec2 create-vpc --cidr-block 10.0.0.0/16

  2. 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

  3. 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

  4. 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

  5. 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}'

  6. 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:

  1. Describe instance status:

    aws ec2 describe-instance-status

  2. 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

  3. Describe volumes:

    aws ec2 describe-volumes

  4. Create a key pair:

    aws ec2 create-key-pair --key-name MyKeyPair --query 'KeyMaterial' --output text > MyKeyPair.pem

  5. 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

  6. 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:

  1. Create an S3 bucket:

    aws s3 mb s3://<bucket-name>

  2. Remove an S3 bucket:

    aws s3 rb s3://bucket-name

  3. List S3 buckets:

    aws s3 ls

  4. 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:

  1. 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

Did you find this article valuable?

Support Ashoksana by becoming a sponsor. Any amount is appreciated!