Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jonathanwcrane's full-sized avatar

Jonathan Crane jonathanwcrane

  • Washington, DC
View GitHub Profile
@jonathanwcrane
jonathanwcrane / Purge_CloudWatchAlarms.py
Last active March 27, 2024 09:42
Purge CloudWatch alarms for instances that no longer exist
#Step 1: Get a list of all alarms in INSUFFICIENT_DATA status
#Step 2: Get a list of all instances (stopped and started)
#Step 3: Find all alarms on instances that don't exist, and delete them
###################################################
#Step 1: Get alarms in INSUFFICENT_DATA state
###################################################
#The max that we can get per loop is 100; all alarms for nonexistent instances will be in
#INSUFFICIENT_DATA state so let's just go through those.
insuff_alarms = []
loops = 1
#!/usr/bin/env python
#inventory a bucket
import boto3
import re
import os
import logging
import random
from random import choice
from string import ascii_uppercase
@jonathanwcrane
jonathanwcrane / mpu.py
Last active September 26, 2020 22:52
Find failed multipart uploads in all buckets in a region
#!/usr/bin/env python
#inventory of all multipart uploads in a region
import boto3
import os
#Not sure this applies here but keeping just in case
region = "us-east-1"
#The profile to use in the credentials or boto.config file, if used
profile_nm = 'foo'
@jonathanwcrane
jonathanwcrane / rename_serviceaccounts.py
Created January 14, 2016 18:16
Working code to find non-interactive IAM users (service accounts)
for user in iam.users.all():
# Nothing is initially loaded
profile = user.LoginProfile()
try:
profile.load()
# We don't care if this works
except ClientError as e:
if 'NoSuchEntity' in e.response['Error']['Code']:
nm = user.name
#print(nm,"is a service account.")