Skip to content

Instantly share code, notes, and snippets.

View kevinkarwaski's full-sized avatar

Kevin Karwaski kevinkarwaski

View GitHub Profile
import boto3
import json
import logging
import time
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def notify_on_error(message):
"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",
"myLifecycleHookTopic" : {
"Type" : "AWS::SNS::Topic",
"Properties" : {
"Subscription" : [
{ "Endpoint" : { "Fn::GetAtt" : [ "MyLambdaLifecycleFunction", "Arn" ] }, "Protocol" : "lambda" }
]
}
}
"myLifecycleHook": {
"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" ] }
}
@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)

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 / 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
@kevinkarwaski
kevinkarwaski / install-brew.sh
Last active September 13, 2023 21:34
Install Brew and set up for Standard OSX User
#!/usr/bin/env bash
# This script installs brew and chowns the right directories needed to run
# brew as a standard user. Your user should be the owner of /usr/local which
# gets set during the installation of brew. The global homebrew cache directory
# group should be set to 'staff' which is not set during a brew install. This
# script fixes that.
# To begin, you MUST execute this script with your user account while it has
# admin privileges. Once the script completes, you can change your
@kevinkarwaski
kevinkarwaski / b2dntp
Last active August 29, 2015 14:10 — forked from mmcc/b2dntp
#!/bin/sh
# Fix NTP/Time
# https://github.com/boot2docker/boot2docker/issues/290
boot2docker ssh -- sudo killall -9 ntpd
boot2docker ssh -- sudo ntpclient -s -h pool.ntp.org
boot2docker ssh -- sudo ntpd -p pool.ntp.org
@kevinkarwaski
kevinkarwaski / Kevin_Karwaski_pub
Last active May 30, 2018 18:01
PGP Public Key
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: Mailvelope v2.2.2
Comment: https://www.mailvelope.com
xsFNBFsO5ogBEAC5zWoeOdrDO3SYVG+3/1vsiPQG7IZP3WZghjLhCVd1tZXS
ZeZihtAhRKolaTFYLyZ1YspgANylnNU3G5BdbfqLXyEcApY9bpQbmu6VbslW
H6289/N22VposWApzQ/g6vmwFv2ey/U4uJZ5M9xHGEmjOk0ZKDA5nBG6sP02
KqbMauqYQowUZ6fHiDAYIwOqVBBXczXqmwin1o3Om76mrEJuQAdmEaFkVZ+a
bSlhMF6rhwOwMWPjA0YfpUUidbMGlgf/SmIAj/EU+NLwFCi4B2Mv6ybuXsc8
h+rLSrC+rx2XSLS4P6bZeZYUzPSGDa7qp42IrMZgLphpQclionAfooNuTpux