Skip to content

Instantly share code, notes, and snippets.

@hatchcanon
hatchcanon / bucketcheck.sh
Last active June 16, 2021 21:03
list encryption status of all S3 buckets
for bucket_name in $(aws s3api list-buckets --query "Buckets[].Name" --output text); do
echo -ne "${bucket_name},"
encryption_info=$(aws s3api get-bucket-encryption \
--bucket ${bucket_name} 2>/dev/null)
if [[ $? != 0 ]]; then
echo "no-encryption"
else
echo "${encryption_info}"
fi
done
@hatchcanon
hatchcanon / ssmdescribe.sh
Created April 29, 2021 02:09
list all the AWS instances that are missing the SSM agent
#!/bin/bash
for instance in $(aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId]' --output text )
do
managed=$(aws ssm describe-instance-information --filters "Key=InstanceIds,Values=$instance" --query 'InstanceInformationList[*].[AssociationStatus]' --output text)
if [[ "$managed" != "Success" ]]; then
managed=" Not Managed";
fi
aws ec2 describe-instances --instance-id $instance --output text --query 'Reservations[*].Instances[*].[InstanceId, Placement.AvailabilityZone, [Tags[?Key==`Name`].Value] [0][0], [Tags[?Key==`App`].Value] [0][0], [Tags[?Key==`Product`].Value] [0][0], [Tags[?Key==`Team`].Value] [0][0] ]'
echo " $managed"
done
@hatchcanon
hatchcanon / termprotect.sh
Created April 15, 2021 15:44
termination protection list generator
#!/bin/bash
for instance in $(aws ec2 describe-instances --region us-east-1 | grep InstanceId | cut -d '"' -f 4 | sort); do
echo -n $instance
aws ec2 describe-instance-attribute --instance-id $instance --attribute disableApiTermination | grep Value | cut -d : -f 2
done
@hatchcanon
hatchcanon / snaptrash.sh
Created April 5, 2021 21:30
bulk delete multiple AWS snapshots using AWS CLI
file="filewithsnapshotids.txt"
cat $file | tr -d '\r' | while read -r line;
do
aws ec2 delete-snapshot --snapshot-id $line
echo "Deleting snapshot $line"
done
@hatchcanon
hatchcanon / aws-backup-vault-purge.sh
Last active January 31, 2021 20:02
Removes all recovery points from a specific time frame inside a AWS Backup vault
#!/bin/bash
VAULT_NAME=""
echo "Enter the name of the vault where all backups should be deleted"
read -t 10 VAULT_NAME || exit
# be sure to change the by-created-before and by-created-after to your liking
for ARN in $(aws backup list-recovery-points-by-backup-vault --backup-vault-name "${VAULT_NAME}" --by-created-before "2021-01-28T21:28:00/-0600" --by-created-after "2021-01-28T21:26:00/-0600" --query 'RecoveryPoints[].RecoveryPointArn' --output text --region us-east-1); do
echo "deleting ${ARN} ..."
aws backup delete-recovery-point --region us-east-1 --backup-vault-name "${VAULT_NAME}" --recovery-point-arn "${ARN}"

Keybase proof

I hereby claim:

  • I am hatchcanon on github.
  • I am ncho (https://keybase.io/ncho) on keybase.
  • I have a public key ASABvm2bJ2mYKlq_n007LHjAt0ZbrhSzskDyZk3BBTcqxAo

To claim this, I am signing this object: