mirror of
https://github.com/LeCoupa/awesome-cheatsheets.git
synced 2026-01-29 22:58:04 -08:00
Compare commits
3 Commits
master
...
364186037b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
364186037b | ||
|
|
54aef9e7d0 | ||
|
|
df2f5d47d7 |
77
tools/aws.sh
77
tools/aws.sh
@@ -3,37 +3,62 @@
|
|||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
# General
|
# General
|
||||||
aws help
|
##############################################################################
|
||||||
aws --version # Show the current AWS CLI version
|
|
||||||
aws configure # Configure your AWS Key ID, AWS Secret, default region and default output format for the AWS CLI
|
|
||||||
aws configure --profile <profile_name> # Configure using the profile name. By default, the list of profile is stored in ~/.aws.credentials (Linux and MacOS)
|
|
||||||
|
|
||||||
# EC2
|
aws sts get-caller-identity # Returns details about the IAM user or role whose credentials are used to call the operation
|
||||||
## We need to specify a region to use ec2 commands. We can configure a default region with "aws configure" or set the AWS_DEFAULT_REGION environment variable before the command line
|
|
||||||
## Example: AWS_DEFAULT_REGION=us-east-1 aws ec2 describe-instances
|
|
||||||
|
|
||||||
aws ec2 describe-instances # Desribe all instances in the current region
|
# AWS Lambda
|
||||||
aws ec2 describe-instances --instance-ids <instance_id_1> <instance_id_2> # Describe specific instances by their IDs
|
##############################################################################
|
||||||
aws ec2 describe-instances --filters Name=<instance_name> # Filter and describe instances by name
|
|
||||||
|
|
||||||
aws ec2 start-instances --instance-ids <instance_id_1> <instance_id_2> # Start previously stopped instances by their IDs
|
aws lambda update-function-code --function-name MyFunction --zip-file fileb://myCode.zip # Update the code of an existing Lambda function
|
||||||
aws ec2 stop-instances --instance-ids <instance_id_1> <instance_id_2> # Stop running instances by their IDs
|
aws lambda add-permission --function-name MyFunction --action lambda:InvokeFunction --principal apigateway.amazonaws.com --statement-id Id-1 # Add permission to the Lambda function
|
||||||
aws ec2 terminate-instances --instance-ids <instance_id_1> <instance_id_2> # Shutdown the specific instances by their IDs
|
|
||||||
|
|
||||||
|
# AWS DynamoDB
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
# S3
|
aws dynamodb put-item --table-name MyTable --item '{ "Name": {"S": "ItemName"}, "Attribute": {"S": "AttributeValue"}}' # Add an item to 'MyTable'
|
||||||
## To specify the root directory of a S3 bucket, use this syntax: s3://<bucket_name>
|
aws dynamodb get-item --table-name MyTable --key '{ "Name": {"S": "ItemName"}}' # Retrieve an item from 'MyTable'
|
||||||
|
aws dynamodb update-item --table-name MyTable --key '{ "Name": {"S": "ItemName"}}' --update-expression "SET Attribute = :val1" --expression-attribute-values '{":val1": {"S": "NewAttributeValue"}}' # Update an item in 'MyTable'
|
||||||
|
|
||||||
aws s3 ls # List S3 objects and common prefixes under a prefix or all S3 buckets
|
# AWS IAM
|
||||||
aws s3 ls s3://<bucket_name> # List objects and common prefixes under a specified bucket and prefix
|
##############################################################################
|
||||||
aws s3 mb s3://<bucket_name> # Create a specific S3 bucket
|
|
||||||
aws s3 rb s3://<bucket_name> # Remove an empty specific S3 bucket by name
|
|
||||||
|
|
||||||
aws s3 mv <local_file_path> s3://<bucket_name>/<destination_file_path> # Move a file in local_file_path to a specific bucket in destination_file_path
|
aws iam attach-user-policy --user-name MyUser --policy-arn arn:aws:iam::aws:policy/AmazonS3FullAccess # Attach a policy to a user
|
||||||
## Example: aws s3 mv text.txt s3://mybucket/text.txt
|
aws iam detach-user-policy --user-name MyUser --policy-arn arn:aws:iam::aws:policy/AmazonS3FullAccess # Detach a policy from a user
|
||||||
aws s3 mv s3://<bucket_name_1> s3://<bucket_name_2> --recursive # Move all objects from bucket_name_1 to bucket_name_2
|
aws iam create-policy --policy-name MyPolicy --policy-document file://mypolicy.json # Create a new policy
|
||||||
|
aws iam delete-policy --policy-arn arn:aws:iam::aws:policy/MyPolicy # Delete a policy
|
||||||
|
|
||||||
aws s3 sync <source> <target> # Sync all contents from source to a target directory. This will copy and update all missing or outdated files or objects between source and target
|
# AWS CloudWatch
|
||||||
## Examples: aws s3 sync . s3://mybucket
|
##############################################################################
|
||||||
## aws s3 sync s3://bucket_1 s3://bucket_2
|
|
||||||
aws s3 sync <source> <target> --delete # Sync all contents from source to target, but this will remove all missing files and objects from the target that are not present in source
|
aws cloudwatch get-metric-data --metric-data-queries file://queries.json --start-time 2023-01-01T00:00:00Z --end-time 2023-01-02T00:00:00Z # Retrieve metric data
|
||||||
|
aws cloudwatch put-metric-data --metric-name MyMetric --namespace MyNamespace --value 1 # Publish a metric
|
||||||
|
aws cloudwatch enable-alarm-actions --alarm-name MyAlarm # Enable actions for an alarm
|
||||||
|
aws cloudwatch disable-alarm-actions --alarm-name MyAlarm # Disable actions for an alarm
|
||||||
|
|
||||||
|
# AWS S3
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
aws s3 cp s3://mybucket/myfile.txt . # Copy a file from S3 to local
|
||||||
|
aws s3 rm s3://mybucket/myfile.txt # Delete a file from S3
|
||||||
|
aws s3api put-object-acl --bucket mybucket --key myfile.txt --acl public-read # Set S3 file to public
|
||||||
|
aws s3api create-bucket --bucket mynewbucket --region us-west-1 # Create a new S3 bucket in a specific region
|
||||||
|
aws s3api delete-object --bucket mybucket --key myfile.txt # Delete an object from a bucket
|
||||||
|
|
||||||
|
# Additional AWS Services
|
||||||
|
# AWS RDS (Relational Database Service)
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
aws rds describe-db-instances # Describe all RDS instances
|
||||||
|
aws rds stop-db-instance --db-instance-identifier MyDbInstance # Stop an RDS instance
|
||||||
|
aws rds start-db-instance --db-instance-identifier MyDbInstance # Start an RDS instance
|
||||||
|
aws rds delete-db-instance --db-instance-identifier MyDbInstance --skip-final-snapshot # Delete an RDS instance without creating a final snapshot
|
||||||
|
|
||||||
|
# AWS Route 53
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
aws route53 list-hosted-zones # List all hosted zones
|
||||||
|
aws route53 create-hosted-zone --name mydomain.com --caller-reference 1 # Create a new hosted zone
|
||||||
|
aws route53 delete-hosted-zone --id /hostedzone/Z2FDTNDATAQYW2 # Delete a hosted zone
|
||||||
|
aws route53 list-resource-record-sets --hosted-zone-id /hostedzone/Z2FDTNDATAQYW2 # List all records in a hosted zone
|
||||||
|
aws route53 change-resource-record-sets --hosted-zone-id /hostedzone/Z2FDTNDATAQYW2 --change-batch file://changes.json # Change records in a hosted zone
|
||||||
|
|||||||
Reference in New Issue
Block a user