AWS Cheatsheet
In fact checking AWS setup, the AWS CLI offers fast and efficient outcomes with a straightforward means of reporting for assurance.
for region in `aws ec2 describe-regions --output text | cut -f3`
do
echo -e "\nListing Instances in region:'$region'..."
aws ec2 describe-instances --region $region
done$ aws configservice subscribe --s3-bucket ${bucketname} --sns-topic arn:aws:sns:us-east-2:012345678912:my-config-notice --iam-role arn:aws:iam::012345678912:role/myConfigRole
$aws ec2 modify-volume --region us-east-1--volume-idvol-11111111111111111--size200--volume-typeio1 --iops10000
aws ec2 describe-instances --query "Reservations[*].Instances[*].[InstanceId,LaunchTime<='2016-11-01',BlockDeviceMappings[*][Ebs.AttachTime<='2016-11-01']]" --output text
aws iam create-instance-profile
aws iam create-instance-profile --instance-profile-name CloudControl
aws ec2 describe-instances
#extend volume
aws ec2 modify-volume --region eu-central-1 --volume-id vol-01a44e2347d859de6 --size 20 --volume-type gp2
#create volume
aws ec2 create-volume --region eu-central-1 --availability-zone eu-central-1b --size 2 --volume-type gp2Cloudtrail – Logging and Auditing
http://docs.aws.amazon.com/cli/latest/reference/cloudtrail/
# list all trails
aws cloudtrail describe-trails
# list all S3 buckets
aws s3 ls
# create a new trail
aws cloudtrail create-subscription \
--name awslog \
--s3-new-bucket awslog2016
# list the names of all trails
aws cloudtrail describe-trails --output text | cut -f 8
# get the status of a trail
aws cloudtrail get-trail-status \
--name awslog
# delete a trail
aws cloudtrail delete-trail \
--name awslog
# delete the S3 bucket of a trail
aws s3 rb s3://awslog2016 --force
# add tags to a trail, up to 10 tags
aws cloudtrail add-tags \
--resource-id awslog \
--tags-list "Key=log-type,Value=all"
# list the tags of a trail
aws cloudtrail list-tags \
--resource-id-list
# remove a tag from a trail
aws cloudtrail remove-tags \
--resource-id awslog \
--tags-list "Key=log-type,Value=all"# list all user's info
aws iam list-users
# list all user's usernames
aws iam list-users --output text | cut -f 6
# list current user's info
aws iam get-user
# list current user's access keys
aws iam list-access-keys
# crate new user
aws iam create-user \
--user-name aws-admin2
# create multiple new users, from a file
allUsers=$(cat ./user-names.txt)
for userName in $allUsers; do
aws iam create-user \
--user-name $userName
done
# list all users
aws iam list-users --no-paginate
# get a specific user's info
aws iam get-user \
--user-name aws-admin2
# delete one user
aws iam delete-user \
--user-name aws-admin2
# delete all users
# allUsers=$(aws iam list-users --output text | cut -f 6);
allUsers=$(cat ./user-names.txt)
for userName in $allUsers; do
aws iam delete-user \
--user-name $userName
done# list existing S3 buckets
aws s3 ls
# create a bucket name, using the current date timestamp
bucket_name=test_$(date "+%Y-%m-%d_%H-%M-%S")
echo $bucket_name
# create a public facing bucket
aws s3api create-bucket --acl "public-read-write" --bucket $bucket_name
# verify bucket was created
aws s3 ls | grep $bucket_name
# check for public facing s3 buckets (should show the bucket name you created)
aws s3api list-buckets --query 'Buckets[*].[Name]' --output text | xargs -I {} bash -c 'if [[ $(aws s3api get-bucket-acl --bucket {} --query '"'"'Grants[?Grantee.URI==`http://acs.amazonaws.com/groups/global/AllUsers` && Permission==`READ`]'"'"' --output text) ]]; then echo {} ; fi'
# check for public facing s3 buckets, updated them to be private
aws s3api list-buckets --query 'Buckets[*].[Name]' --output text | xargs -I {} bash -c 'if [[ $(aws s3api get-bucket-acl --bucket {} --query '"'"'Grants[?Grantee.URI==`http://acs.amazonaws.com/groups/global/AllUsers` && Permission==`READ`]'"'"' --output text) ]]; then aws s3api put-bucket-acl --acl "private" --bucket {} ; fi'
# check for public facing s3 buckets (should be empty)
aws s3api list-buckets --query 'Buckets[*].[Name]' --output text | xargs -I {} bash -c 'if [[ $(aws s3api get-bucket-acl --bucket {} --query '"'"'Grants[?Grantee.URI==`http://acs.amazonaws.com/groups/global/AllUsers` && Permission==`READ`]'"'"' --output text) ]]; then echo {} ; fi'# list all keypairs
# http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-key-pairs.html
aws ec2 describe-key-pairs
# create a keypair
# http://docs.aws.amazon.com/cli/latest/reference/ec2/create-key-pair.html
aws ec2 create-key-pair \
--key-name <value> --output text
# create a new local private / public keypair, using RSA 4096-bit
ssh-keygen -t rsa -b 4096
# import an existing keypair
# http://docs.aws.amazon.com/cli/latest/reference/ec2/import-key-pair.html
aws ec2 import-key-pair \
--key-name keyname_test \
--public-key-material file:///home/apollo/id_rsa.pub
# delete a keypair
# http://docs.aws.amazon.com/cli/latest/reference/ec2/delete-key-pair.html
aws ec2 delete-key-pair \
--key-name <value># list all private AMI's, ImageId and Name tags
aws ec2 describe-images --filter "Name=is-public,Values=false" \
--query 'Images[].[ImageId, Name]' \
--output text | sort -k2
# delete an AMI, by ImageId
aws ec2 deregister-image --image-id ami-00000000# list the tags of an instance
# http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-tags.html
aws ec2 describe-tags
# add a tag to an instance
# http://docs.aws.amazon.com/cli/latest/reference/ec2/create-tags.html
aws ec2 create-tags \
--resources "ami-1a2b3c4d" \
--tags Key=name,Value=debian
# delete a tag on an instance
# http://docs.aws.amazon.com/cli/latest/reference/ec2/delete-tags.html
aws ec2 delete-tags \
--resources "ami-1a2b3c4d" \
--tags Key=Name,Value=
0 comments