Home » #Technology » Essential AWS CLI Commands and Their Usage

Essential AWS CLI Commands and Their Usage

Now that you’ve successfully installed and configured the AWS CLI on your Mac using my earlier tech blog posts, it’s time to dive into some of the most useful commands to help you manage your AWS resources more efficiently, just like a tech pro. In this tech concept, I will share a selection of AWS CLI commands that our team uses daily. Practicing these commands will help you get a better grasp of working efficiently with AWS CLI and automating processes. Below are some handy AWS CLI commands and their usage, categorized by service.

1. S3 (Simple Storage Service)

Amazon S3 is a scalable storage service that allows you to store and retrieve large amounts of data from anywhere on the web. Using the AWS CLI, you can perform various operations on your S3 buckets and objects, such as listing, creating, uploading, downloading, and deleting them. Here are some key commands for managing your S3 resources.

List Buckets

aws s3 ls

This command lists all your S3 buckets.

Create a New Bucket

aws s3 mb s3://your-bucket-name

This command creates a new S3 bucket.

Upload a File to a Bucket

aws s3 cp local-file-path s3://your-bucket-name

This command uploads a file from your local system to an S3 bucket.

Download a File from a Bucket

aws s3 cp s3://your-bucket-name/remote-file-path local-file-path

This command downloads a file from an S3 bucket to your local system.

Delete a Bucket

aws s3 rb s3://your-bucket-name --force

This command deletes an S3 bucket and all its contents.

2. EC2 (Elastic Compute Cloud)

Amazon EC2 provides scalable computing capacity in the AWS cloud, allowing you to run virtual servers known as instances. With the AWS CLI, you can manage your EC2 instances easily, including starting, stopping, and terminating instances, as well as creating key pairs for secure access. Here are some essential EC2 commands.

List Instances

aws ec2 describe-instances

This command lists all your EC2 instances along with their details.

Start an Instance

aws ec2 start-instances --instance-ids i-1234567890abcdef0

This command starts an EC2 instance using its instance ID.

Stop an Instance

aws ec2 stop-instances --instance-ids i-1234567890abcdef0

This command stops an EC2 instance using its instance ID.

Terminate an Instance

aws ec2 terminate-instances --instance-ids i-1234567890abcdef0

This command terminates an EC2 instance using its instance ID.

Create a Key Pair

aws ec2 create-key-pair --key-name MyKeyPair

This command creates a new key pair and saves the private key to a file.

3. IAM (Identity and Access Management)

IAM allows you to manage access to AWS services and resources securely. With IAM, you can create and manage AWS users and groups, and use permissions to allow and deny their access to AWS resources. The AWS CLI provides commands to help you handle various IAM tasks, such as listing users, creating users, and managing policies.

List Users

aws iam list-users

This command lists all IAM users in your AWS account.

Create a User

aws iam create-user --user-name new-user

This command creates a new IAM user.

Delete a User

aws iam delete-user --user-name user-to-delete

This command deletes an IAM user.

Attach a Policy to a User

aws iam attach-user-policy --user-name user-name --policy-arn arn:aws:iam::aws:policy/PolicyName

This command attaches a managed policy to an IAM user.

4. Lambda

AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consume. With the AWS CLI, you can manage your Lambda functions, including listing, creating, invoking, and deleting them. Here are some key Lambda commands.

List Functions

aws lambda list-functions

This command lists all your Lambda functions.

Invoke a Function

aws lambda invoke --function-name function-name output-file

This command invokes a Lambda function and saves the output to a file.

Create a Function

aws lambda create-function --function-name function-name --runtime runtime --role role-arn --handler handler --zip-file fileb://file-path

This command creates a new Lambda function from a ZIP file.

Delete a Function

aws lambda delete-function --function-name function-name

This command deletes a Lambda function.

5. CloudFormation

AWS CloudFormation allows you to model and set up your AWS resources so that you can spend less time managing those resources and more time focusing on your applications. With CloudFormation, you can use a template file to create and delete a collection of resources as a single unit. The AWS CLI commands help you manage these stacks efficiently.

List Stacks

aws cloudformation list-stacks

This command lists all your CloudFormation stacks.

Create a Stack

aws cloudformation create-stack --stack-name stack-name --template-body file://template-file

This command creates a new CloudFormation stack from a template file.

Delete a Stack

aws cloudformation delete-stack --stack-name stack-name

This command deletes a CloudFormation stack.

My Tech Advice: These are just a few examples of the powerful commands available with the AWS CLI. By mastering these commands, you can automate and streamline your workflows, manage your AWS resources more effectively, and fully leverage AWS services. As a tech advisor and entrepreneur, I always encourage my clients to ensure their tech teams work like pros—staying open to new technologies and continuously learning. Keep exploring and experimenting with the AWS CLI to uncover even more opportunities! Happy cloud computing! 🧑🏻‍💻🧙‍♀️

#AskDushyant
#AWS #CLI #CloudComputing #DevOps #TechPro #Automation #AWSCLIInstallation #Terminal #TechBlog #CloudManagement #AWSResources

Leave a Reply

Your email address will not be published. Required fields are marked *