Skip to content

Instantly share code, notes, and snippets.

View rafaotetra's full-sized avatar

Rafael Silva rafaotetra

View GitHub Profile
@rafaotetra
rafaotetra / netpps.sh
Last active August 29, 2015 14:07 — forked from joemiller/netpps.sh
#!/bin/bash
if [ -z "$1" ]; then
echo
echo usage: $0 network-interface
echo
echo e.g. $0 eth0
echo
echo shows packets-per-second
@rafaotetra
rafaotetra / snapshots.py
Created September 29, 2017 15:31 — forked from Eyjafjallajokull/README.md
AWS EBS - Find unused snapshots - this script generates csv raport about snapshot usage
import re
import boto3
import csv
from botocore.exceptions import ClientError
ec2 = boto3.client('ec2')
def get_snapshots():
return ec2.describe_snapshots(OwnerIds=['self'])['Snapshots']
@rafaotetra
rafaotetra / EC2-Tag-Assets-Lambda.py
Last active October 3, 2017 10:58 — forked from mlapida/EC2-Tag-Assets-Lambda.py
A lambda function that will copy EC2 tags to all related Volumes and Network Interfaces. A full writeup can be found on my site http://mlapida.com/thoughts/tagging-and-snapshotting-with-lambda
from __future__ import print_function
import json
import boto3
import logging
#setup simple logging for INFO
logger = logging.getLogger()
logger.setLevel(logging.ERROR)
@rafaotetra
rafaotetra / aws.sg.unused
Created September 29, 2017 23:36 — forked from thibautsacreste/aws.sg.unused
Bash: list unused AWS security groups
#!/usr/bin/env bash
# lists all unused AWS security groups.
# a group is considered unused if it's not attached to any network interface.
# requires aws-cli and jq.
# all groups
aws ec2 describe-security-groups \
| jq --raw-output '.SecurityGroups[] | [.GroupName, .GroupId] | @tsv' \
| sort > /tmp/sg.all
@rafaotetra
rafaotetra / cleanup.py
Created October 4, 2017 15:49 — forked from luhn/cleanup.py
An AWS Lambda function to delete old AMIs.
"""
Code adapted from and inspired by http://blog.ranman.org/cleaning-up-aws-with-boto3/.
"""
import os
import re
from datetime import datetime, timedelta
import boto3
@rafaotetra
rafaotetra / function.py
Created October 10, 2017 19:39 — forked from brandond/function.py
Python script to auto-tag AWS EBS Snapshots and Volumes using AMI and Instance tags
import copy
import logging
import os
import boto3
logging.basicConfig(level=os.environ.get('LOG_LEVEL', 'INFO'))
ec2 = boto3.client('ec2')
logger = logging.getLogger(__name__)
@rafaotetra
rafaotetra / iamlookup
Created October 11, 2017 09:44 — forked from aelsabbahy/iamlookup
Simple script to lookup IAM resource conditions
#!/bin/bash
set -e
REPO_DIR=~/.iam_lookup/complete-aws-iam-reference
REPO_URL=https://github.com/widdix/complete-aws-iam-reference
if [[ $1 == "update" ]];then
if [[ -e $REPO_DIR ]];then
(cd "$REPO_DIR" && git pull)
else
@rafaotetra
rafaotetra / pg_backup_db_script.sh
Created October 25, 2017 15:43 — forked from ppatelcodal/pg_backup_db_script.sh
BASH Script to backup RDS/EC2 PostgreSQL DB and upload to S3 weekly
#!/bin/bash
# Run as sudo. for weekly backup of db. and upload to s3 bucket.
DBHOME="/home/priyank/crontabs/dbbackups/"
BUCKETNAME="yourAWSbucket"
SCRIPTNAME="$(basename $BASH_SOURCE)"
SCRIPTFULLPATH="$(pwd)/$(basename $BASH_SOURCE)"
mkdir -p $DBHOME
chown -R postgres:postgres $DBHOME
cp $SCRIPTFULLPATH $DBHOME
SCHEMA_BACKUP="$DBHOME/$(date +%w).sql"
import os
import sys
import time
import argparse
import boto3
if os.environ.get('AWS_PROFILE') is None:
sys.exit('Environment variable AWS_PROFILE not set')
argparser = argparse.ArgumentParser(description='Snapshot EC2 instance volume with volume ID specified by argument')
import os
import sys
import time
import argparse
import boto3
if os.environ.get('AWS_PROFILE') is None:
sys.exit('Environment variable AWS_PROFILE not set')
argparser = argparse.ArgumentParser(description='Snapshot EC2 instance volume with volume ID specified by argument')