Skip to content

Instantly share code, notes, and snippets.

View akinnard's full-sized avatar

Allen Kinnard akinnard

  • Arizona
View GitHub Profile
@akinnard
akinnard / .bashrc
Created January 29, 2017 21:51
AWS bashrc alias commands
# list all instances that are not terminated, useful for greping for a server(s); aws-instance --profile myprofile | grep myserver
alias aws-instances="aws ec2 describe-instances --filters Name=instance-state-name,Values=running,pending,shutting-down,stopping,stopped --output table --query 'Reservations[].Instances[].{InstanceId:InstanceId,KeyName:KeyName,InstanceType:InstanceType,LaunchTime:LaunchTime,PrivateIpAddress:PrivateIpAddress,PublicIpAddress:PublicIpAddress, InstanceNameTag:Tags[?Key==\`Name\`].Value | [0], State:State.Name}'"
# list all ami's shared with your account
alias aws-images="aws ec2 describe-images --owners 99999999999999 --query 'Images[*].[Name,ImageId,CreationDate,Description]'"
# list all rds servers, just like aws-instances
alias aws-rds="aws rds describe-db-instances --query 'DBInstances[*].[DBInstanceIdentifier,DBInstanceClass,Engine,EngineVersion,AllocatedStorage,StorageType,DBInstanceStatus]' --output table"
# list all snap shots, usefull for grepping a specific rds server
alias
@akinnard
akinnard / r53-cleanup.py
Last active February 22, 2019 04:14
Clean up a private hosted zone in route53
#!/usr/local/bin/python3
import sys
import boto3
import argparse
import requests
import json
from datetime import datetime
from colorama import Fore, Back, Style
@akinnard
akinnard / gist:4921f08f59d582cce83efab65d6254e2
Created April 24, 2016 03:55
In a chef template, use the recipe runlist in an if statement.
<% if node['recipes'].include? "recipe-name" %>
attributes=true
<% else %>
attribute=false
<% end %>
@akinnard
akinnard / unusedrds.sh
Created March 13, 2016 06:32
Find unused rds instances
osname=$( uname )
if [[ $osname == "Darwin" ]]; then
date="gdate"
else
date="date"
fi
MYVER="0.1"
MYHOST=$(hostname -s)
MYDATETIME=$($date +%Y%m%d%H%M)
@akinnard
akinnard / gist:24136d28fbc24b48952e
Created January 29, 2016 00:45
Get s3 buckets size by day (last modified)
aws s3api list-objects --bucket your-bucket-here --output text --query 'Contents[*].{ Size:Size, LastModified:LastModified}' | awk '{ $1 = substr($1, 1, 10) } 1' | awk '{count[$1]++; sum[$1]+=$2;}END{for (s in sum){print s, "," ,sum[s], ",", count[s], "&"}}'
@akinnard
akinnard / default.rb
Created January 4, 2016 00:48
Send an email in chef
# use notifies to send en email when the config file changes
template "/etc/my.cnf" do
source "my.cnf.erb"
owner "mysql"
group "mysql"
mode "0650"
notifies :run, "script[sendmail_mycnf]"
end
script "sendmail_mycnf" do