Learn AWS CLI Commands
Contents
- 1 General AWS CLI Commands
- 2 Amazon S3 CLI Commands
- 3 Amazon EC2 CLI Commands
- 4 AWS IAM CLI Commands
- 5 Amazon RDS CLI Commands
- 6 AWS Lambda CLI Commands
- 7 AWS CloudFormation CLI Commands
- 8 Amazon SNS CLI Commands
- 9 Amazon SQS CLI Commands
- 10 Amazon CloudWatch CLI Commands
- 11 Amazon VPC CLI Commands
- 12 Amazon Route 53 CLI Commands
General AWS CLI Commands
- Configure CLI
Set up AWS CLI with user credentials and default settings:
aws configure
- Check CLI Version
Display the current version of AWS CLI:
aws --version
- Get Service Documentation
Access help documentation for AWS CLI commands:
aws help
Amazon S3 CLI Commands
- List S3 Buckets
View all the S3 buckets in your account:
aws s3 ls
- Upload a Local File to S3
Upload a file from your local system to an S3 bucket:
aws s3 cp localfile.txt s3://bucket-name/
- Download a File from S3
Retrieve a file from an S3 bucket to your local directory:
aws s3 cp s3://bucket-name/file.txt ./
- View Bucket Contents
List all files in a specific S3 bucket:
aws s3 ls s3://bucket-name/
- Remove a File from S3
Delete a file in an S3 bucket:
aws s3 rm s3://bucket-name/file.txt
- Synchronize Local and S3
Sync a local folder with an S3 bucket:
aws s3 sync local-dir/ s3://bucket-name/
Amazon EC2 CLI Commands
- Show EC2 Instances
Display details of all your EC2 instances:
aws ec2 describe-instances
- Start EC2 Instance
Boot up a specified EC2 instance:
aws ec2 start-instances --instance-ids i-1234567890abcdef0
- Stop EC2 Instance
Stop a running EC2 instance:
aws ec2 stop-instances --instance-ids i-1234567890abcdef0
- Terminate EC2 Instance
Terminate a given EC2 instance:
aws ec2 terminate-instances --instance-ids i-1234567890abcdef0
- Generate EC2 Key Pair
Create a new key pair for EC2:
aws ec2 create-key-pair --key-name MyKeyPair
- List Key Pairs
View all your EC2 key pairs:
aws ec2 describe-key-pairs
- Create Security Group
Create a new security group:
aws ec2 create-security-group --group-name MySecurityGroup --description "My security group"
AWS IAM CLI Commands
- List IAM Users
Display all IAM users in your account:
aws iam list-users
- Add IAM User
Create a new IAM user:
aws iam create-user --user-name new-user
- Attach Policy to User
Attach a policy to a specific IAM user:
aws iam attach-user-policy --user-name new-user --policy-arn arn:aws:iam::aws:policy/PolicyName
- List IAM Roles
Show all IAM roles:
aws iam list-roles
- Create IAM Role
Establish a new IAM role:
aws iam create-role --role-name MyRole --assume-role-policy-document file://policy.json
Amazon RDS CLI Commands
- List RDS Instances
View all RDS database instances:
aws rds describe-db-instances
- Create RDS Instance
Launch a new RDS instance:
aws rds create-db-instance --db-instance-identifier mydb --db-instance-class db.t2.micro --engine mysql --master-username master --master-user-password password
- Delete RDS Instance
Delete an RDS instance:
aws rds delete-db-instance --db-instance-identifier mydb --skip-final-snapshot
AWS Lambda CLI Commands
- List Lambda Functions
View all Lambda functions:
aws lambda list-functions
- Create Lambda Function
Deploy a new Lambda function:
aws lambda create-function --function-name MyFunction --runtime python3.8 --role arn:aws:iam::123456789012:role/service-role/MyRole --handler lambda_function.lambda_handler --zip-file fileb://function.zip
- Invoke Lambda Function
Call a specific Lambda function:
aws lambda invoke --function-name MyFunction output.json
- Update Lambda Function Code
Update the code for a Lambda function:
aws lambda update-function-code --function-name MyFunction --zip-file fileb://function.zip
- Delete Lambda Function
Remove a Lambda function:
aws lambda delete-function --function-name MyFunction
AWS CloudFormation CLI Commands
- List CloudFormation Stacks
Show details of all CloudFormation stacks:
aws cloudformation describe-stacks
- Create CloudFormation Stack
Create a new stack with a template:
aws cloudformation create-stack --stack-name MyStack --template-body file://template.json
- Update CloudFormation Stack
Update an existing stack using a new template:
aws cloudformation update-stack --stack-name MyStack --template-body file://template.json
- Delete CloudFormation Stack
Delete a specific CloudFormation stack:
aws cloudformation delete-stack --stack-name MyStack
Amazon SNS CLI Commands
- List SNS Topics
Display all SNS topics:
aws sns list-topics
- Create SNS Topic
Establish a new SNS topic:
aws sns create-topic --name MyTopic
- Subscribe to SNS Topic
Add an email subscription to an SNS topic:
aws sns subscribe --topic-arn arn:aws:sns:region:account-id:MyTopic --protocol email --notification-endpoint email@example.com
- Send Message to SNS Topic
Publish a message to an SNS topic:
aws sns publish --topic-arn arn:aws:sns:region:account-id:MyTopic --message "Hello World"
- List SNS Subscriptions
Show all SNS subscriptions:
aws sns list-subscriptions
Amazon SQS CLI Commands
- List SQS Queues
Display all SQS queues:
aws sqs list-queues
- Create SQS Queue
Set up a new SQS queue:
aws sqs create-queue --queue-name MyQueue
- Send Message to SQS Queue
Send a message to an SQS queue:
aws sqs send-message --queue-url https://sqs.region.amazonaws.com/account-id/MyQueue --message-body "Hello World"
- Receive Message from SQS Queue
Retrieve a message from an SQS queue:
aws sqs receive-message --queue-url https://sqs.region.amazonaws.com/account-id/MyQueue
- Delete SQS Queue
Remove an SQS queue:
aws sqs delete-queue --queue-url https://sqs.region.amazonaws.com/account-id/MyQueue
Amazon CloudWatch CLI Commands
- List CloudWatch Alarms
View all CloudWatch alarms:
aws cloudwatch describe-alarms
- Create CloudWatch Alarm
Set up a new CloudWatch alarm:
aws cloudwatch put-metric-alarm --alarm-name MyAlarm --metric-name CPUUtilization --namespace AWS/EC2 --statistic Average --period 300 --threshold 70 --comparison-operator GreaterThanOrEqualToThreshold --evaluation-periods 2 --alarm-actions arn:aws:sns:region:account-id:MyTopic
- Delete CloudWatch Alarm
Remove a CloudWatch alarm:
aws cloudwatch delete-alarms --alarm-names MyAlarm
Amazon VPC CLI Commands
- List VPCs
Display all VPCs in your account:
aws ec2 describe-vpcs
- Create VPC
Establish a new VPC:
aws ec2 create-vpc --cidr-block 10.0.0.0/16
- Delete VPC
Remove a VPC:
aws ec2 delete-vpc --vpc-id vpc-12345678
- Describe VPC Subnets
List all subnets in a VPC:
aws ec2 describe-subnets
Amazon Route 53 CLI Commands
- List Hosted Zones
Display all Route 53 hosted zones:
aws route53 list-hosted-zones
- Create Hosted Zone
Create a new DNS hosted zone:
aws route53 create-hosted-zone --name example.com --caller-reference unique-string
- Delete Hosted Zone
Remove a DNS hosted zone:
aws route53 delete-hosted-zone --id Z3M3LMPEXAMPLE
- List Route 53 Records
Show DNS records in a hosted zone:
aws route53 list-resource-record-sets --hosted-zone-id Z3M3LMPEXAMPLE