Skip to content

Instantly share code, notes, and snippets.

View kevinkarwaski's full-sized avatar

Kevin Karwaski kevinkarwaski

View GitHub Profile
#!/usr/bin/env bash
# Oneliner to remove all gems.
# See: http://stackoverflow.com/questions/15100496/uninstalling-all-gems-ruby-2-0-0
for i in `gem list --no-versions`; do gem uninstall -aIx $i; done
@kevinkarwaski
kevinkarwaski / gist:5340928
Last active December 15, 2015 23:29
Limited S3 IAM policy for Cloudability
{
"Statement":[
{
"Action": "s3:ListAllMyBuckets",
"Effect": "Allow",
"Resource": "arn:aws:s3:::*"
},
{
"Action":["s3:ListBucket","s3:GetObject","s3:GetObjectVersion"],
"Effect":"Allow",

Requirements

  • Docker Machine + Docker
  • curl
  • A Virtualbox-driven Docker Machine called "default".

Usage

The git.io URL (https://git.io/v2MHR) is a shortened form of the raw url of the plist.

@kevinkarwaski
kevinkarwaski / nuke_docker
Created April 15, 2016 19:37
Because sometimes you just need to purge it all.
#!/bin/bash
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)
"myLifecycleHook": {
"Type": "AWS::AutoScaling::LifecycleHook",
"Properties": {
"AutoScalingGroupName": { "Ref": "myAutoScalingGroup" },
"HeartbeatTimeout": 300,
"LifecycleTransition": "autoscaling:EC2_INSTANCE_TERMINATING",
"NotificationMetadata": { "Ref": "StackName" },
"NotificationTargetARN": { "Ref": "lifecycleHookTopic" },
"RoleARN": { "Fn::GetAtt": [ "lifecycleHookRole", "Arn" ] }
}
"myLifecycleHookTopic" : {
"Type" : "AWS::SNS::Topic",
"Properties" : {
"Subscription" : [
{ "Endpoint" : { "Fn::GetAtt" : [ "MyLambdaLifecycleFunction", "Arn" ] }, "Protocol" : "lambda" }
]
}
}
"myLifecycleHook": {
#!/usr/bin/env bash -e
# Install Codeship's JET cli tool for Docker on OSX (brew-less).
# https://codeship.com/documentation/docker/installation/#mac-os-x
# https://codeship.com/documentation/docker/release-notes/
JET_VERSION=1.9.3
FILE_NAME=jet-darwin_amd64_${JET_VERSION}.tar.gz
CHECKSUM=sha256sums
"MyLambdaLifecycleFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Handler": "asg-graceful-lifecycle-termination.lambda_handler",
"Role": { "Fn::GetAtt" : ["LambdaExecutionRole", "Arn"] },
"Code": {
"S3Bucket": "lambda-functions",
"S3Key": "asg-graceful-lifecycle-termination.zip"
},
"Runtime": "python2.7",
@kevinkarwaski
kevinkarwaski / curlHeaders
Created March 3, 2015 20:41
Curl response headers helper
#!/usr/bin/env bash
# Return only response headers from Curl.
#
# Usage: curlHeaders http://www.someaddress.com
curl -k -s -D - $1 -o /dev/null
import boto3
import json
import logging
import time
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def notify_on_error(message):