Skip to content

Instantly share code, notes, and snippets.

View ianblenke's full-sized avatar
🎯
Focusing

Ian Blenke ianblenke

🎯
Focusing
View GitHub Profile
@ianblenke
ianblenke / elasticbeanstalk_mysqldump.sh
Created July 30, 2015 13:46
Processing the DATABASE_URL for an elasticbeanstalk app to do a mysqldump
DATABASE_URL=$(sudo /opt/elasticbeanstalk/bin/get-config environment | jq .DATABASE_URL)
fields=( $(echo $DATABASE_URL | sed -e 's/^"mysql2:\/\/\([^:]*\):\([^@]*\)@\([^:]*\):\([^/]*\)\/\([^\?]*\)\?.*$/\1 \2 \3 \4 \5/') )
docker exec -ti $(docker ps -a | grep web | awk '{print $1}') mysqldump -h ${fields[2]} -u ${fields[0]} --password="${fields[1]}" -P ${fields[3]} ${fields[4]} > ${fields[4]}.sql
@ianblenke
ianblenke / prune_eb_versions.sh
Last active March 8, 2019 16:46
Delete any ElasticBeanstalk application versions older than a week old that are not currently in use by an environment.
awsargs="--profile aws-dev --region us-east-1"
now=$(date -j -f "%a %b %d %T %Z %Y" "$(date)" "+%s" 2>/dev/null);
oneweekago=$(expr $now - 604800);
aws elasticbeanstalk describe-application-versions $awsargs | \
jq -r '.ApplicationVersions[] | .ApplicationName + " " + .VersionLabel + " " + .DateCreated'| \
while read line ; do
fields=( $line )
utime=$(date -j -f %Y-%m-%dT%H:%M:%S "${fields[2]};" "+%s" 2>/dev/null);
if [[ $utime -lt $oneweekago ]]; then
if [ -n "$(aws elasticbeanstalk describe-environments $awsargs \
@ianblenke
ianblenke / .ebextensions_00_tune_ec2.config_.yaml
Created July 23, 2015 19:12
Tuning EC2 with an ElasticBeanstalk ebextension
packages:
yum:
wget: []
curl: []
commands:
00_remove_99_swap.conf.bak:
command: rm -f /etc/sysctl.d/99_swap.conf.bak
test: test -f /etc/sysctl.d/99_swap.conf.bak
ignoreErrors: true
00_remove_99_filesystem.conf.bak:
@ianblenke
ianblenke / make-outputs.json
Last active August 29, 2015 14:23
Sample output from running gist 55b740ff19825d621ef4 Makefile: make outputs
aws cloudformation describe-stacks --stack-name myapp-dev --profile aws-dev --region us-east-1 | jq -r '.Stacks[].Outputs'
[
{
"Description": "VPC Id",
"OutputKey": "VpcId",
"OutputValue": "vpc-b7d1d8d2"
},
{
"Description": "VPC",
"OutputKey": "VPCDefaultNetworkAcl",
@ianblenke
ianblenke / Makefile
Last active October 7, 2019 12:35
A Makefile for creating, updating, watching, and deleting a CloudFormation VPC as per gists 9f4b8dd2b39c7d1c31ef and 0a6a6f26d1ecaa0d81eb
STACK:=myapp-dev
TEMPLATE:=cloudformation-template_vpc-iam.json
PARAMETERS:=cloudformation-parameters_myapp-dev.json
AWS_REGION:=us-east-1
AWS_PROFILE:=aws-dev
all:
@which aws || pip install awscli
aws cloudformation create-stack --stack-name $(STACK) --template-body file://`pwd`/$(TEMPLATE) --parameters file://`pwd`/$(PARAMETERS) --capabilities CAPABILITY_IAM --profile $(AWS_PROFILE) --region $(AWS_REGION)
@ianblenke
ianblenke / cloudformation-parameters_myapp-dev.json
Created June 27, 2015 19:03
An example CloudFormation parameters file for the VPC Template in gist 0a6a6f26d1ecaa0d81eb
[
{ "ParameterKey": "Project", "ParameterValue": "myapp" },
{ "ParameterKey": "Environment", "ParameterValue": "dev" },
{ "ParameterKey": "VPCNetworkCIDR", "ParameterValue": "10.0.0.0/16" },
{ "ParameterKey": "VPCSubnet0CIDR", "ParameterValue": "10.0.0.0/24" },
{ "ParameterKey": "VPCSubnet1CIDR", "ParameterValue": "10.0.1.0/24" },
{ "ParameterKey": "VPCSubnet2CIDR", "ParameterValue": "10.0.2.0/24" }
]
@ianblenke
ianblenke / cloudformation-template_vpc-iam.json
Created June 27, 2015 18:55
AWS CloudFormation Template example for VPC with IAM Instance Profile
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "MyApp VPC",
"Parameters" : {
"Project" : {
"Description" : "Project name to tag resources with",
"Type" : "String",
"MinLength": "1",
"MaxLength": "16",
"AllowedPattern" : "[a-z]*",
# See http://help.papertrailapp.com/kb/hosting-services/aws-elastic-beanstalk/
sources:
/home/ec2-user: https://github.com/papertrail/remote_syslog2/releases/download/<VERSION>/remote_syslog_linux_amd64.tar.gz
files:
"/etc/log_files.yml":
mode: "00644"
owner: root
group: root
@ianblenke
ianblenke / elasticbeanstalk_application_version.sh
Created May 12, 2015 20:41
Discovering the currently deployed version on an elasticbeanstalk EC2 instance
AWS_DEFAULT_REGION=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .region)
EC2_INSTANCE_ID=$(curl -sL http://169.254.169.254/latest/meta-data/instance-id)
EB_ENVIRONMENT_ID=$(aws ec2 describe-tags --filter Name=resource-id,Values=$EC2_INSTANCE_ID --region $AWS_DEFAULT_REGION | jq -r '.Tags | .[] | select(.Key=="elasticbeanstalk:environment-id") | .Value')
EB_APPLICATION_VERSION=$(aws elasticbeanstalk describe-environments --environment-ids $EB_ENVIRONMENT_ID --region $AWS_DEFAULT_REGION --region $AWS_DEFAULT_REGION | jq -r '.Environments | .[] | .VersionLabel')
@ianblenke
ianblenke / remove_dead_newrelic_servers.sh
Created May 2, 2015 17:57
Remove non-reporting NewRelic servers
curl -sLX GET 'https://api.newrelic.com/v2/servers.json' \
-H "X-Api-Key:${NEW_RELIC_API_KEY}" | \
jq -r '.servers | [ .[] | select(.reporting == 'false') ] | .[] | ."id" ' | \
xargs -L1 -I% curl -X DELETE 'https://api.newrelic.com/v2/servers/%.json' \
-H "X-Api-Key:${NEW_RELIC_API_KEY}" -i