Skip to content

Instantly share code, notes, and snippets.

@coingraham
coingraham / ami_deleter.py
Last active December 5, 2018 16:50
AMI Delete Python Script - with lambda hooks and exponential backoff
import boto3
from botocore.exceptions import ClientError
from datetime import datetime, timedelta
import time
import os
# region = "eu-central-1"
region = "ap-southeast-1"
# Create custom sessions
@coingraham
coingraham / snapshot_deleter.py
Last active March 14, 2018 14:45
Snapshot Delete Python Script
import sys
import boto3
from botocore.exceptions import ClientError
from datetime import datetime, timedelta
import time
import pytz
profile = "profile name"
region = "us-west-2"
dry_run = True
@coingraham
coingraham / command.sh
Last active July 17, 2019 02:08
AWS Git Credential Helper Debug and with Profile
echo -e "protocol=https\npath=/v1/repos/myrepo\nhost=git-codecommit.us-east-1.amazonaws.com" | aws codecommit credential-helper get --debug
echo -e "protocol=https\npath=/v1/repos/myrepo\nhost=git-codecommit.us-east-1.amazonaws.com" | aws codecommit --profile [profile] credential-helper get --debug
@coingraham
coingraham / Sublime TextPastry
Last active August 9, 2022 13:11
Text Pastry commands for multiline terraform
Highlight `xxxx` then `Command+Control+G` to quick select all
Command+Alt/Option+N then `i 1 1 each=5`
i initial step each=repeat how many times
topic {
id = "${var.jde_s3_prod_bucket_1_notifications_xxxx[1]}"
events = ["${var.jde_s3_prod_bucket_1_notifications_xxxx[2]}"]
filter_prefix = "${var.jde_s3_prod_bucket_1_notifications_xxxx[3]}"
filter_suffix = "${var.jde_s3_prod_bucket_1_notifications_xxxx[4]}"
@coingraham
coingraham / get_bucket_notifications.py
Last active June 1, 2018 04:34
Get S3 bucket notifications
# Pull the s3 bucket notifications and generate the following:
# 1. Terraform resource configuration
# 2. Variable definitions
# 3. TFVars lists
import boto3
profile = "my_profile"
region = "us-east-1"
@coingraham
coingraham / Get_User_By_Access_Key.py
Created September 12, 2017 17:55
Find User by Access Key Python
import boto3
profile = "my_profile"
region = "us-west-2"
session = boto3.session.Session(profile_name=profile, region_name=region)
iam = session.resource("iam")
@coingraham
coingraham / emr.type.sql
Created August 31, 2017 20:01
Athena SQL
SELECT
eventtime,
CASE
when useridentity.type = 'IAMUser' then useridentity.username
when useridentity.type = 'Root' then useridentity.invokedby
when useridentity.type = 'AssumedRole' then useridentity.arn
ELSE
'undefined'
END as "userid",
sourceipaddress,
@coingraham
coingraham / example.sql
Created August 29, 2017 13:32
Athena SQL
Select
eventtime,
CASE
when useridentity.type = 'IAMUser' then useridentity.username
when useridentity.type = 'Root' then useridentity.invokedby
when useridentity.type = 'AssumedRole' then useridentity.arn
ELSE
'undefined'
END as "userid",
sourceipaddress,
@coingraham
coingraham / service_url.text
Last active December 20, 2017 23:52
List of Service URLS
acm.amazonaws.com
apigateway.amazonaws.com
athena.amazonaws.com
autoscaling.amazonaws.com
clouddirectory.amazonaws.com
cloudformation.amazonaws.com
cloudfront.amazonaws.com
cloudsearch.amazonaws.com
cloudtrail.amazonaws.com
codecommit.amazonaws.com
@coingraham
coingraham / delete_snapshots.py
Last active August 14, 2017 22:26 — forked from kjoconnor/delete_snapshots.py
boto script to delete snapshots matching a filter and older than X days
import sys
import boto3
from botocore.exceptions import ClientError
from datetime import datetime, timedelta
import time
import pytz
profile = "my_profile"
region = "us-west-2"
dry_run = True