Skip to content

Instantly share code, notes, and snippets.

View jcaxmacher's full-sized avatar
💭
Focused

J Axmacher jcaxmacher

💭
Focused
View GitHub Profile
@jcaxmacher
jcaxmacher / get_rest_apigws.py
Created May 12, 2021 20:00
Get list of API Gateway REST APIs
import csv
import boto3
rest_apis = []
ec2 = boto3.client('ec2', region_name='us-east-1')
for region in ec2.describe_regions()['Regions']:
print(f"Checking region {region['RegionName']}")
session = boto3.Session(region_name=region['RegionName'])
apigw = session.client('apigateway')
for api in apigw.get_rest_apis()['items']:
@jcaxmacher
jcaxmacher / get_patch_list.py
Created May 12, 2021 19:56
get list of patches present on EC2 instance
import csv
import boto3
ec2 = boto3.client('ec2', region_name='us-west-1')
ssm = boto3.client('ssm', region_name='us-west-1')
response = ec2.describe_instances(
Filters=[
{'Name':'tag:workload','Values':['somethin']},
{'Name':'tag:environment','Values':['prod']}
@jcaxmacher
jcaxmacher / health-event-types.json
Created May 12, 2021 14:25
AWS Health Event Types
{
"eventTypes": [
{
"service": "A4B",
"code": "AWS_A4B_API_ISSUE",
"category": "issue"
},
{
"service": "A4B",
"code": "AWS_A4B_CALENDAR_CONNECTIVITY_FAILURE",
@jcaxmacher
jcaxmacher / .gitconfig
Created May 12, 2021 14:23
Git config
[user]
email = jeremy@obsoleter.com
name = Jeremy A
[push]
default = current
[credential]
helper = /mnt/c/Program\\ Files/Git/mingw64/libexec/git-core/git-credential-manager.exe
@jcaxmacher
jcaxmacher / Makefile
Created May 12, 2021 14:22
Python Project Makefile
# system python interpreter. used only to create virtual environment
PY = python3
VENV = venv
BIN=$(VENV)/bin
# make it work on windows too
ifeq ($(OS), Windows_NT)
BIN=$(VENV)/Scripts
PY=python
endif
@jcaxmacher
jcaxmacher / retry.py
Created February 18, 2021 20:02
Python Requests Retry
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
def get_requests_retry_session():
retries = Retry(total=5, backoff_factor=1, status_forcelist=[429, 500, 502, 503, 504])
adapter = HTTPAdapter(max_retries=retries)
http = requests.Session()
http.mount("https://", adapter)
http.mount("http://", adapter)
@jcaxmacher
jcaxmacher / rmvpc.py
Created January 16, 2021 04:32 — forked from alberto-morales/rmvpc.py
Deleting an AWS VPC with python's boto3
#!/usr/bin/env python
"""I was trying to programatically remove a Virtual Private Cloud (VPC) in
AWS and the error message was not helpful:
botocore.exceptions.ClientError: An error occurred (DependencyViolation)
when calling the DeleteVpc operation: The vpc 'vpc-c12029b9' has
dependencies and cannot be deleted.
Searching for a quick solution was not fruitful but I was able to glean some
knowledge from Neil Swinton's gist:
@jcaxmacher
jcaxmacher / blame.sh
Created September 23, 2020 20:04
Git blame and comment in every file
#!/bin/bash
for file in $(git ls-files); do
commits=`git blame $file | cut -f1 -d' ' | sort -u`
count=`git blame $file | cut -f1 -d' ' | sort -u | wc -l`
comments=""
for commit in $commits; do
newcommit=`echo $commit | sed -e 's/^\^//g'`
@jcaxmacher
jcaxmacher / blame.sh
Created September 1, 2020 04:52
Generate change table for specific file using git commit history
#!/bin/bash
file=$1
commits=`git blame $file | cut -f1 -d' ' | sort -u`
count=`git blame $file | cut -f1 -d' ' | sort -u | wc -l`
for commit in $commits; do
newcommit=`echo $commit | sed -e 's/^\^//g'`
user=`git show -s --format='%an' $newcommit`
@jcaxmacher
jcaxmacher / LambdaEfsBackup.py
Created June 17, 2020 01:36 — forked from eduardcloud/LambdaEfsBackup.py
Backup EFS file-system to S3 with lambda function
import boto3
import time
region = 'eu-west-1'
user_data_script = """#!/bin/bash
instanceid=$(curl http://169.254.169.254/latest/meta-data/instance-id)
cd /
mkdir moodledata
mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 fs-xxxxxxxxxxc.efs.eu-west-1.amazonaws.com:/ moodledata
tar czf mooodledata-backup-$(date +%d-%m-%Y_%H-%M).tar.gz /moodledata
aws s3 mv mooodledata-backup-*.tar.gz s3://xxxxxxxxx/