Favorite AWS Cli command(s)

  • This will copy all the objects from one S3 bucket to another —

aws s3 cp s3://bucket1 s3://bucket2  –recursive   –grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers full=emailaddress=awsaccountemailaddress

*if bucket2 is in a different AWS account, it will need a bucket policy allowing bucket1 user to write to it.

  • This will list running instances’ instanceID, privateIP, and Tag=Name —

    aws ec2 describe-instances –filters “Name=instance-state-code”,”Values=16″ –query “Reservations[*].Instances[*].[InstanceId, PrivateIpAddress, Tags[?Key==’Name’].Value | [0]]” –output table –region us-east-1 –profile production

  • This will export running instances’  InstanceID, InstanceType, Tag=Name, Tag=Project to a .tsv file (linux) which Excel will be able to open —

aws ec2 describe-instances –output text –filters “Name=instance-state-code”,”Values=16″ –query ‘Reservations[*].Instances[*].[InstanceId, InstanceType,  [Tags[?Key==`Name`].Value] [0][0], [Tags[?Key==`Project`].Value] [0][0]]’ > test.tsv

  • This will decode an AWS error —

aws sts decode-authorization-message –encoded-message <superlongcrypticmessage>