AWS CLI Commands

The AWS CLI (Command Line Interface) is a unified tool provided by Amazon Web Services (AWS) that allows you to manage and interact with your AWS services from a command line or terminal. It provides a way to automate tasks and perform operations programmatically without using the AWS Management Console.

To start using the AWS CLI, you need to install it on your machine, configure it with your AWS credentials (aws configure) , and then you’re ready to run commands.

Here’s a concise list of commonly used AWS CLI commands:

AWS CLI Basics

1. Configuration:

aws configure

Set up your AWS CLI with access key, secret key, region, and output format.

2. General Command Structure:

aws <service> <operation> <subcommand> [parameters]

Common Commands by Service

S3 (Simple Storage Service)

List Buckets:

aws s3 ls

Create a Bucket:

aws s3 mb s3://my-bucket

Delete a Bucket:

aws s3 rb s3://my-bucket

Upload a File:

aws s3 cp myfile.txt s3://my-bucket/

Download a File:

aws s3 cp s3://my-bucket/myfile.txt myfile.txt

Sync Directories:

aws s3 sync mydir s3://my-bucket/mydir

Related: Fixing 5 Common AWS IAM Errors

IAM (Identity and Access Management)

List Users:

aws iam list-users

Create User:

aws iam create-user --user-name my-user

Delete User:

aws iam delete-user --user-name my-user

Attach Policy to User:

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

Related: AWS ECS vs AWS EKS: How To Choose?

EC2 (Elastic Compute Cloud)

List Instances:

aws ec2 describe-instances

Start an Instance:

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

Stop an Instance:

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

Terminate an Instance:

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

RDS (Relational Database Service)

List Databases:

aws rds describe-db-instances

Create Database Instance:

aws rds create-db-instance --db-instance-identifier mydbinstance --db-instance-class db.t2.micro --engine mysql --master-username admin --master-user-password password --allocated-storage 20

Delete Database Instance:

aws rds delete-db-instance --db-instance-identifier mydbinstance --skip-final-snapshot

Lambda

List Functions:

aws lambda list-functions

Invoke a Function:

aws lambda invoke --function-name my-function out.txt

Deploy a Function:

aws lambda create-function --function-name my-function --zip-file fileb://function.zip --handler my-handler --runtime nodejs12.x --role arn:aws:iam::account-id:role/execution_role

SNS (Simple Notification Service)

List Topics:

aws sns list-topics

Create Topic:

aws sns create-topic --name my-topic

Publish to a Topic:

aws sns publish --topic-arn arn:aws:sns:us-east-1:123456789012:my-topic --message "Hello World"

Delete Topic:

aws sns delete-topic --topic-arn arn:aws:sns:us-east-1:123456789012:my-topic

CloudFormation

List Stacks:

aws cloudformation list-stacks

Create Stack:

aws cloudformation create-stack --stack-name my-stack --template-body file://template.json

Delete Stack:

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

Additional Useful Commands

Check AWS CLI Version:

aws --version

Get Help:

aws help

aws <service> help

aws <service> <operation> help

Dry Run Mode:

aws <service> <operation> --dry-run

Leave a Comment

Select your currency
USD United States (US) dollar