Learn AWS CLI Commands

General AWS CLI Commands

  1. Configure CLI
    Set up AWS CLI with user credentials and default settings:
    aws configure
  2. Check CLI Version
    Display the current version of AWS CLI:
    aws --version
  3. Get Service Documentation
    Access help documentation for AWS CLI commands:
    aws help

Amazon S3 CLI Commands

  1. List S3 Buckets
    View all the S3 buckets in your account:
    aws s3 ls
  2. 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/
  3. Download a File from S3
    Retrieve a file from an S3 bucket to your local directory:
    aws s3 cp s3://bucket-name/file.txt ./
  4. View Bucket Contents
    List all files in a specific S3 bucket:
    aws s3 ls s3://bucket-name/
  5. Remove a File from S3
    Delete a file in an S3 bucket:
    aws s3 rm s3://bucket-name/file.txt
  6. Synchronize Local and S3
    Sync a local folder with an S3 bucket:
    aws s3 sync local-dir/ s3://bucket-name/

Amazon EC2 CLI Commands

  1. Show EC2 Instances
    Display details of all your EC2 instances:
    aws ec2 describe-instances
  2. Start EC2 Instance
    Boot up a specified EC2 instance:
    aws ec2 start-instances --instance-ids i-1234567890abcdef0
  3. Stop EC2 Instance
    Stop a running EC2 instance:
    aws ec2 stop-instances --instance-ids i-1234567890abcdef0
  4. Terminate EC2 Instance
    Terminate a given EC2 instance:
    aws ec2 terminate-instances --instance-ids i-1234567890abcdef0
  5. Generate EC2 Key Pair
    Create a new key pair for EC2:
    aws ec2 create-key-pair --key-name MyKeyPair
  6. List Key Pairs
    View all your EC2 key pairs:
    aws ec2 describe-key-pairs
  7. Create Security Group
    Create a new security group:
    aws ec2 create-security-group --group-name MySecurityGroup --description "My security group"

AWS IAM CLI Commands

  1. List IAM Users
    Display all IAM users in your account:
    aws iam list-users
  2. Add IAM User
    Create a new IAM user:
    aws iam create-user --user-name new-user
  3. 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
  4. List IAM Roles
    Show all IAM roles:
    aws iam list-roles
  5. 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

  1. List RDS Instances
    View all RDS database instances:
    aws rds describe-db-instances
  2. 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
  3. Delete RDS Instance
    Delete an RDS instance:
    aws rds delete-db-instance --db-instance-identifier mydb --skip-final-snapshot

AWS Lambda CLI Commands

  1. List Lambda Functions
    View all Lambda functions:
    aws lambda list-functions
  2. 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
  3. Invoke Lambda Function
    Call a specific Lambda function:
    aws lambda invoke --function-name MyFunction output.json
  4. Update Lambda Function Code
    Update the code for a Lambda function:
    aws lambda update-function-code --function-name MyFunction --zip-file fileb://function.zip
  5. Delete Lambda Function
    Remove a Lambda function:
    aws lambda delete-function --function-name MyFunction

AWS CloudFormation CLI Commands

  1. List CloudFormation Stacks
    Show details of all CloudFormation stacks:
    aws cloudformation describe-stacks
  2. Create CloudFormation Stack
    Create a new stack with a template:
    aws cloudformation create-stack --stack-name MyStack --template-body file://template.json
  3. Update CloudFormation Stack
    Update an existing stack using a new template:
    aws cloudformation update-stack --stack-name MyStack --template-body file://template.json
  4. Delete CloudFormation Stack
    Delete a specific CloudFormation stack:
    aws cloudformation delete-stack --stack-name MyStack

Amazon SNS CLI Commands

  1. List SNS Topics
    Display all SNS topics:
    aws sns list-topics
  2. Create SNS Topic
    Establish a new SNS topic:
    aws sns create-topic --name MyTopic
  3. 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
  4. 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"
  5. List SNS Subscriptions
    Show all SNS subscriptions:
    aws sns list-subscriptions

Amazon SQS CLI Commands

  1. List SQS Queues
    Display all SQS queues:
    aws sqs list-queues
  2. Create SQS Queue
    Set up a new SQS queue:
    aws sqs create-queue --queue-name MyQueue
  3. 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"
  4. 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
  5. 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

  1. List CloudWatch Alarms
    View all CloudWatch alarms:
    aws cloudwatch describe-alarms
  2. 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
  3. Delete CloudWatch Alarm
    Remove a CloudWatch alarm:
    aws cloudwatch delete-alarms --alarm-names MyAlarm

Amazon VPC CLI Commands

  1. List VPCs
    Display all VPCs in your account:
    aws ec2 describe-vpcs
  2. Create VPC
    Establish a new VPC:
    aws ec2 create-vpc --cidr-block 10.0.0.0/16
  3. Delete VPC
    Remove a VPC:
    aws ec2 delete-vpc --vpc-id vpc-12345678
  4. Describe VPC Subnets
    List all subnets in a VPC:
    aws ec2 describe-subnets

Amazon Route 53 CLI Commands

  1. List Hosted Zones
    Display all Route 53 hosted zones:
    aws route53 list-hosted-zones
  2. Create Hosted Zone
    Create a new DNS hosted zone:
    aws route53 create-hosted-zone --name example.com --caller-reference unique-string
  3. Delete Hosted Zone
    Remove a DNS hosted zone:
    aws route53 delete-hosted-zone --id Z3M3LMPEXAMPLE
  4. List Route 53 Records
    Show DNS records in a hosted zone:
    aws route53 list-resource-record-sets --hosted-zone-id Z3M3LMPEXAMPLE