AWS CLI: Commands for S3, EC2, Lambda, IAM, RDS, DynamoDB, SQS, SNS, CloudFormation, ECR, EKS, SSM, CloudWatch, Route 53, Kinesis
The AWS Command Line Interface (CLI) is a unified tool that provides a consistent interface for interacting with all parts of AWS. AWS CLI supports multiple AWS services and the list is quite extensive. Below are examples of AWS CLI commands for some commonly used services.
1. AWS S3 (Simple Storage Service)
aws s3 ls
– List S3 buckets.aws s3 cp [local_file] s3://[bucket_name]/[path_to_file]
– Upload a local file to an S3 bucket.aws s3 rm s3://[bucket_name]/[file_name]
– Delete a file from an S3 bucket.aws s3 sync s3://[source_bucket] s3://[destination_bucket]
– Sync files between two S3 buckets.
2. AWS EC2 (Elastic Compute Cloud)rong>
aws ec2 describe-instances
– Describe EC2 instances.aws ec2 start-instances --instance-ids [instance_id]
– Start an EC2 instance.aws ec2 stop-instances --instance-ids [instance_id]
– Stop an EC2 instance.aws ec2 terminate-instances --instance-ids [instance_id]
– Terminate an EC2 instance.
3. AWS Lambda
aws lambda list-functions
– List Lambda functions.aws lambda create-function --function-name [function_name]
– Create a new Lambda function.aws lambda invoke --function-name [function_name] outputfile.txt - Invoke a Lambda function and output the result to a file.
aws lambda delete-function --function-name [function_name]
- Delete a Lambda function.
4. AWS IAM (Identity and Access Management)
aws iam list-users
- List IAM users.aws iam get-user --user-name [user_name]
- Get details of an IAM user.aws iam create-user --user-name [user_name]
- Create an IAM user.aws iam delete-user --user-name [user_name]
- Delete an IAM user.
5. AWS RDS (Relational Database Service)
aws rds describe-db-instances - Describe RDS instances.
aws rds start-db-instance --db-instance-identifier [db_identifier]
- Start an RDS instance.aws rds stop-db-instance --db-instance-identifier [db_identifier]
- Stop an RDS instance.aws rds delete-db-instance --db-instance-identifier [db_identifier]
- Delete an RDS instance.
6. AWS DynamoDB (NoSQL Database Service)
aws dynamodb list-tables - List DynamoDB tables.
aws dynamodb describe-table --table-name [table_name]
- Describe a DynamoDB table.aws dynamodb create-table --table-name [table_name]
- Create a new DynamoDB table. This requires additional parameters for specifying key schema and attributes.aws dynamodb delete-table --table-name [table_name]
- Delete a DynamoDB table.
7. AWS SQS (Simple Queue Service)ong>
aws sqs list-queues - List SQS queues.
aws sqs send-message --queue-url [queue_url] --message-body "[message_body] - Send a message to an SQS queue.
aws sqs receive-message --queue-url [queue_url]
- Receive a message from an SQS queue.aws sqs delete-message --queue-url [queue_url] --receipt-handle [receipt_handle]
- Delete a message from an SQS queue.
8. AWS SNS (Simple Notification Service)
aws sns list-topics
- List SNS topics.aws sns publish --topic-arn [topic_arn] --message "[message]"
- Publish a message to an SNS topic.aws sns subscribe --topic-arn [topic_arn] --protocol [protocol] --notification-endpoint [endpoint]
- Subscribe an endpoint to an SNS topic.aws sns unsubscribe --subscription-arn [subscription_arn]
- Unsubscribe from an SNS topic.
9. AWS CloudFormation
aws cloudformation list-stacks - List CloudFormation stacks.
aws cloudformation create-stack --stack-name [stack_name] --template-body file://[template_file.json]
- Create a CloudFormation stack.aws cloudformation describe-stack-events --stack-name [stack_name]
- Describe events for a CloudFormation stack.aws cloudformation delete-stack --stack-name [stack_name]
- Delete a CloudFormation stack.
10. AWS ECR (Elastic Container Registry)
aws ecr get-login-password --region [region] | docker login --username AWS --password-stdin [aws_account_id].dkr.ecr.[region].amazonaws.com - Authenticate Docker to an ECR registry.
aws ecr create-repository --repository-name [repo_name]
- Create an ECR repository.aws ecr describe-repositories
- Describe ECR repositories.aws ecr delete-repository --repository-name [repo_name]
- Delete an ECR repository.
11. AWS EKS (Elastic Kubernetes Service)rong>
aws eks list-clusters - List EKS clusters.
aws eks describe-cluster --name [cluster_name]
- Describe an EKS cluster.aws eks update-kubeconfig --region [region] --name [cluster_name]
- Update your kubeconfig with the EKS cluster configuration.
12. AWS SSM (Systems Manager)
aws ssm get-parameter --name [parameter_name]
- Get a parameter from SSM parameter store.aws ssm put-parameter --name [parameter_name] --value [value] --type String
- Put a new parameter into the SSM parameter store.
13. AWS CloudWatch
aws cloudwatch describe-alarms
- Describe CloudWatch alarms.aws cloudwatch put-metric-data --metric-name [metric_name] --namespace [namespace] --value [value]
- Put new metric data into CloudWatch.
14. AWS Route 53
aws route53 list-hosted-zones
- List Route53 hosted zones.aws route53 list-resource-record-sets --hosted-zone-id [hosted_zone_id]
- List resource record sets in a specific hosted zone.
15. AWS Kinesis
aws kinesis list-streams
- List Kinesis data streams.aws kinesis get-shard-iterator --stream-name [stream_name] --shard-id [shard_id] --shard-iterator-type LATEST
- Get a shard iterator for a specific shard.aws kinesis put-record --stream-name [stream_name] --data [data] --partition-key [partition_key]
- Put a record into a Kinesis data stream.
Please replace the placeholder text in brackets ([...]
) with your actual values. Note that the above commands may require additional parameters depending on your specific use case. Always refer to the official AWS CLI Command Reference for more information.
You can install the AWS CLI on Linux, macOS, and Windows, and configure it using the aws configure
command. Remember to securely manage your AWS access keys.
Leave a Comment