Skip to content

Instantly share code, notes, and snippets.

View rwiggins's full-sized avatar

Reid Wiggins rwiggins

View GitHub Profile
@rwiggins
rwiggins / s3_bucket_stats.py
Last active July 7, 2023 01:53
Lists the storage size (for all storage types) and tags of all S3 buckets in an account using CloudWatch's GetMetricStatistics. Uses the default AWS credentials in your environment. (See awscli configuration for more information.)
import boto3
import botocore
import datetime
import progressbar
import itertools
# from https://docs.aws.amazon.com/AmazonS3/latest/dev/cloudwatch-monitoring.html
STORAGE_TYPES = [
"StandardStorage",
"IntelligentTieringStorage",
@rwiggins
rwiggins / userdata.yml
Created May 30, 2018 00:01
Set AWS EC2 instance hostname using cloud-config's bootcmd as userdata. Useful for autoscaling group launch configurations. Uses a prefix + instance ID, useful for Consul hosts for example.
#cloud-config
bootcmd:
- HOSTNAME=my-prefix-"$INSTANCE_ID"
- echo "$HOSTNAME" > /etc/hostname && hostname -F /etc/hostname
- grep -q "127.0.0.1 $HOSTNAME" /etc/hosts || echo "127.0.0.1 $HOSTNAME" >> /etc/hosts
- grep -q "::1 $HOSTNAME" /etc/hosts || echo "::1 $HOSTNAME" >> /etc/hosts