0% found this document useful (0 votes)
32 views9 pages

CLI Commands

Uploaded by

shahnawaz akhtar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views9 pages

CLI Commands

Uploaded by

shahnawaz akhtar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Commonly used AWS CLI commands for managing

EC2 instances:
1. Describe Instances
List all EC2 instances or get details about a specific instance.
bash
aws ec2 describe-instances
aws ec2 describe-instances --instance-ids <instance-id>
2. Launch an EC2 Instance
Launch an instance with a specific AMI ID, instance type, key pair, and security
group.
bash
aws ec2 run-instances --image-id <ami-id> --instance-type <instance-type> \
--key-name <key-pair-name> --security-group-ids <sg-id> --subnet-id <subnet-
id>
3. Stop an EC2 Instance
Stop a running instance.
bash
aws ec2 stop-instances --instance-ids <instance-id>
4. Start an EC2 Instance
Start a stopped instance.
bash
aws ec2 start-instances --instance-ids <instance-id>
5. Reboot an EC2 Instance
Reboot an instance.
bash

aws ec2 reboot-instances --instance-ids <instance-id>


6. Terminate an EC2 Instance
Permanently terminate an instance.
bash
aws ec2 terminate-instances --instance-ids <instance-id>
7. Create an AMI from an Instance
Create a new AMI image from an existing instance.
bash
aws ec2 create-image --instance-id <instance-id> --name <image-name>
8. List Security Groups
View details of all security groups in your account.
bash
aws ec2 describe-security-groups
9. Allocate an Elastic IP
Allocate a new Elastic IP address.
bash
aws ec2 allocate-address
10. Associate an Elastic IP with an Instance
Associate an Elastic IP address with an instance.
bash
aws ec2 associate-address --instance-id <instance-id> --allocation-id <eip-
allocation-id>
11. Describe Key Pairs
List all key pairs in your account.
bash
aws ec2 describe-key-pairs
12. Create a Key Pair
Create a new key pair and save it to a file.
bash
aws ec2 create-key-pair --key-name <key-pair-name> --query 'KeyMaterial' --output
text > <key-file-name>.pem
13. Describe Volumes
List details of all EBS volumes.
bash
aws ec2 describe-volumes
14. Attach an EBS Volume to an Instance
Attach an existing EBS volume to an instance.
bash
aws ec2 attach-volume --volume-id <volume-id> --instance-id <instance-id> --
device /dev/sdf
15. Detach an EBS Volume from an Instance
Detach an EBS volume from an instance.
bash
aws ec2 detach-volume --volume-id <volume-id>

AWS CLI commands for managing Amazon S3:


1. List All Buckets
Lists all the S3 buckets in your account.
bash
aws s3 ls
2. Create a Bucket
Creates a new S3 bucket.
bash
aws s3 mb s3://<bucket-name>
3. Delete a Bucket
Deletes an empty S3 bucket.
bash
aws s3 rb s3://<bucket-name>
For a non-empty bucket, use --force to delete it and all its contents:
bash
aws s3 rb s3://<bucket-name> --force
4. List Bucket Contents
Lists all objects in a specific bucket.
bash
aws s3 ls s3://<bucket-name>
5. Upload a File to a Bucket
Uploads a single file to a bucket.
bash
aws s3 cp <local-file-path> s3://<bucket-name>/<object-key>
6. Download a File from a Bucket
Downloads a single file from a bucket.
bash
aws s3 cp s3://<bucket-name>/<object-key> <local-file-path>
7. Sync Local Directory with S3 Bucket
Syncs the contents of a local directory to an S3 bucket.
bash
aws s3 sync <local-directory-path> s3://<bucket-name>
8. Sync S3 Bucket with Local Directory
Syncs the contents of an S3 bucket to a local directory.
bash
aws s3 sync s3://<bucket-name> <local-directory-path>
9. Copy an Object Within S3
Copies an object from one location in S3 to another (within the same or different
buckets).
bash
aws s3 cp s3://<source-bucket>/<source-object-key>
s3://<destination-bucket>/<destination-object-key>
10. Delete an Object from a Bucket
Deletes a specific object from an S3 bucket.
bash
aws s3 rm s3://<bucket-name>/<object-key>
11. List Object Versions
Lists all versions of objects in a version-enabled bucket.
bash
aws s3api list-object-versions --bucket <bucket-name>
12. Set Bucket Policy
Apply a JSON policy to an S3 bucket.
bash
aws s3api put-bucket-policy --bucket <bucket-name> --policy file://<policy-
file.json>
13. Get Bucket Policy
Retrieve the bucket policy in JSON format.
bash
aws s3api get-bucket-policy --bucket <bucket-name>
14. Enable Bucket Versioning
Enable versioning on an S3 bucket.
bash
aws s3api put-bucket-versioning --bucket <bucket-name> --versioning-
configuration Status=Enabled
15. Enable Server-Side Encryption for a Bucket
Apply a default encryption setting to a bucket.
bash
aws s3api put-bucket-encryption --bucket <bucket-name> --server-side-encryption-
configuration '{
"Rules": [{
"ApplyServerSideEncryptionByDefault": {
"SSEAlgorithm": "AES256"
}
}]
}'
16. Configure Bucket Lifecycle Policy
Apply lifecycle rules for automatic deletion or archiving of objects.
bash
aws s3api put-bucket-lifecycle-configuration --bucket <bucket-name> --lifecycle-
configuration file://<lifecycle-policy.json>
17. Enable Static Website Hosting
Enable and configure static website hosting for a bucket.
bash
aws s3 website s3://<bucket-name>/ --index-document index.html --error-document
error.html

AWS CLI commands for managing DynamoDB:


1. List All Tables
Lists all DynamoDB tables in your account.
bash
aws dynamodb list-tables
2. Create a Table
Creates a new DynamoDB table with specified attributes, key schema, and
provisioned throughput.
bash
aws dynamodb create-table --table-name <table-name> \
--attribute-definitions AttributeName=<attribute-name>,AttributeType=<type> \
--key-schema AttributeName=<attribute-name>,KeyType=<HASH> \
--provisioned-throughput ReadCapacityUnits=<read-
units>,WriteCapacityUnits=<write-units>
3. Describe a Table
Retrieve detailed information about a specific table.
bash
aws dynamodb describe-table --table-name <table-name>
4. Delete a Table
Deletes a specific table.
bash
aws dynamodb delete-table --table-name <table-name>
5. Put an Item into a Table
Inserts or replaces an item in a table.
bash
aws dynamodb put-item --table-name <table-name> --item '{
"PrimaryKey": {"S": "Value1"},
"AttributeName": {"N": "123"}
}'
6. Get an Item from a Table
Retrieves a specific item based on the primary key.
bash
aws dynamodb get-item --table-name <table-name> --key '{
"PrimaryKey": {"S": "Value1"}
}'
7. Update an Item in a Table
Updates specific attributes of an item in a table.
bash
aws dynamodb update-item --table-name <table-name> --key '{
"PrimaryKey": {"S": "Value1"}
}' --update-expression "SET AttributeName = :val" --expression-attribute-values '{
":val": {"S": "NewValue"}
}'
8. Delete an Item from a Table
Deletes a specific item based on the primary key.
bash
aws dynamodb delete-item --table-name <table-name> --key '{
"PrimaryKey": {"S": "Value1"}
}'
9. Query a Table
Queries items in a table based on partition key and optional sort key.
bash
aws dynamodb query --table-name <table-name> --key-condition-expression
"PrimaryKey = :val" \
--expression-attribute-values '{":val": {"S": "Value1"}}'
10. Scan a Table
Scans the entire table, retrieving all items (useful for small tables).
bash
aws dynamodb scan --table-name <table-name>
11. Update Provisioned Throughput for a Table
Modifies the read and write capacity units for a table.
bash
aws dynamodb update-table --table-name <table-name> \
--provisioned-throughput ReadCapacityUnits=<new-read-
units>,WriteCapacityUnits=<new-write-units>
12. List All Backups
Lists all backups for DynamoDB tables.
bash
aws dynamodb list-backups
13. Create a Backup of a Table
Creates a backup for a table.
bash
aws dynamodb create-backup --table-name <table-name> --backup-name
<backup-name>
14. Restore Table from Backup
Restores a table from an existing backup.
bash
aws dynamodb restore-table-from-backup --target-table-name <new-table-name> --
backup-arn <backup-arn>
15. Enable DynamoDB Streams
Enables DynamoDB Streams for a table.
bash
aws dynamodb update-table --table-name <table-name> \
--stream-specification
StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES
16. List Global Tables
Lists all DynamoDB Global Tables in the specified region.
bash
aws dynamodb list-global-tables
17. Create a Global Table
Creates a global table across multiple regions.
bash
aws dynamodb create-global-table --global-table-name <global-table-name> \
--replication-group RegionName=<region1> RegionName=<region2>
18. Update Time to Live (TTL) for a Table
Enables or disables TTL for a specific attribute.
bash
aws dynamodb update-time-to-live --table-name <table-name> \
--time-to-live-specification "Enabled=true, AttributeName=ttl_attribute"

You might also like