AWS CLI Tricks

AWS CLI Command completion

grep "complete -C '/usr/local/bin/aws_completer'" ~/.zshrc > /dev/null

if [ $? -ne 0 ]
then
    echo "complete -C aws_completer aws" >> ~/.zshrc
    source ~/.zshrc
fi
grep "complete -C '/usr/local/bin/aws_completer'" ~/.bashrc > /dev/null

if [ $? -ne 0 ]
then
    echo "complete -C aws_completer aws" >> ~/.bashrc
    source ~/.bashrc
fi

Run an aws command in all regions by getting the region list from EC2 and iterating through it. Use --all-regions to include regions that are not enabled for your account (excluding GovCloud).

Get a list of all unencrypted EC2 volumes

aws ec2 describe-regions --output text --query 'Regions[].[RegionName]'  | while read i; 
do
    aws ec2 describe-volumes --filters Name=encrypted,Values=false --region $i
done

Get a list of all unattached EC2 volumes

aws ec2 describe-regions --output text --query 'Regions[].[RegionName]'  | while read i; 
do
    aws ec2 describe-volumes --filters Name=encrypted,Values=false --region $i
done