Introduction
The AWS Command Line Interface (CLI) is a powerful tool for managing AWS services from the command line. This guide covers installation and usage of the AWS CLI, including common commands for managing EC2 instances, S3 buckets, IAM users, DynamoDB tables, and Lambda functions.
Installation
-
Download and Install AWS CLI
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" unzip awscliv2.zip sudo ./aws/install
-
Verify Installation
aws --version
Basic Configuration
-
Configure AWS CLI
aws configure
-
List AWS CLI Profiles
aws configure list-profiles
Common AWS CLI Commands
EC2 Commands
-
Describe EC2 Instances
aws ec2 describe-instances
S3 Commands
-
Create an S3 Bucket
aws s3api create-bucket --bucket my-bucket-name --region us-east-1
-
List S3 Buckets
aws s3 ls
-
Copy File to S3 Bucket
aws s3 cp my-file.txt s3://my-bucket/
-
List Objects in S3 Bucket
aws s3 ls s3://my-bucket/
-
Copy File from S3 Bucket
aws s3 cp s3://my-bucket/my-file.txt my-local-file.txt
-
Synchronize Local Directory with S3 Bucket
aws s3 sync my-local-directory s3://my-bucket/
-
Remove File from S3 Bucket
aws s3 rm s3://my-bucket/my-file.txt
-
Generate Presigned URL for S3 Object
aws s3 presign s3://my-bucket/my-file.txt
-
Put S3 Bucket Policy
aws s3api put-bucket-policy --bucket my-bucket --policy file://bucket-policy.json
-
Get S3 Bucket ACL
aws s3api get-bucket-acl --bucket my-bucket
-
Enable Versioning on S3 Bucket
aws s3api put-bucket-versioning --bucket my-bucket --versioning-configuration Status=Enabled
-
List Object Versions in S3 Bucket
aws s3api list-object-versions --bucket my-bucket
IAM Commands
-
Create IAM User
aws iam create-user --user-name my-user
-
List IAM Users
aws iam list-users
DynamoDB Commands
-
Create DynamoDB Table
aws dynamodb create-table --table-name MyTable --attribute-definitions AttributeName=ID,AttributeType=N --key-schema AttributeName=ID,KeyType=HASH --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
Lambda Commands
-
List Lambda Functions
aws lambda list-functions
Latest S3 Commands
-
Sync Local Folder to S3 Bucket
aws s3 sync myfolder s3://mybucket
-
Sync Local Folder to S3 Bucket with Delete
aws s3 sync myfolder s3://mybucket --delete
-
Copy File to S3 Bucket
aws s3 cp myfile.txt s3://mybucket/
-
Copy Local Folder to S3 Bucket Recursively
aws s3 cp myfolder s3://mybucket/ --recursive
-
Copy Files from S3 Bucket to Local Folder Recursively
aws s3 cp s3://mybucket/myfolder ./ --recursive
Conclusion
This guide provides essential commands for managing AWS resources using the AWS CLI. From configuring the CLI to performing common tasks with S3, IAM, DynamoDB, and Lambda, these commands help streamline your AWS management processes.
This documentation guide covers the installation, configuration, and usage of the AWS CLI, including specific commands for managing various AWS services and resources.