Skip to content

Instantly share code, notes, and snippets.

View amosshapira's full-sized avatar

Amos Shapira amosshapira

  • Sydney, Australia
View GitHub Profile
@amosshapira
amosshapira / coreid.sh
Created March 21, 2017 22:28 — forked from philcryer/coreid.sh
Get the Amazon CoreOS AMI ID and URL
#!/bin/bash
build=alpha # define build ["stable", "beta", "alpha"]
disk=hvm # define disk backing ["pv", "hvm"]
if [ "x$1" = "x" ]; then
echo "Usage: $0 REGION"; exit 1
fi
#### deprecated
@amosshapira
amosshapira / sort-date.sh
Created March 21, 2017 05:28
Sort on date field using GNU sort
# sample input:
# some-single-word 06/04/2011 03/04/2017
# this will sort on the date field on the third column
# The main trick is the appending of "-n" at the end, for some reason this does it
gsort -b -k 3.7,3.10 -k 3.4,3.5 -k 3.1,3.2 -n
@amosshapira
amosshapira / redirect-domain-with-s3-and-cloudfront.json
Last active May 13, 2018 06:51
CloudFormation template to redirect "company.co.uk" to "company.com"
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Redirect {www.,}company.co.uk web site to company.com, including SSL",
"Resources": {
"BucketCompanyCoUk": {
"Properties": {
"AccessControl": "PublicRead",
"BucketName": "company.co.uk",
"CorsConfiguration": {
"CorsRules": [
@amosshapira
amosshapira / cloudformation.json
Created March 5, 2017 20:12
CloudFormation template to redirect "company.co.uk" to "company.com"
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Redirect company.co.uk web site",
"Resources": {
"BucketCompanyCoUk": {
"Properties": {
"AccessControl": "PublicRead",
"BucketName": "company.co.uk",
"CorsConfiguration": {
"CorsRules": [

Keybase proof

I hereby claim:

  • I am amosshapira on github.
  • I am gliderflyer (https://keybase.io/gliderflyer) on keybase.
  • I have a public key whose fingerprint is B816 AA12 28C0 C9BA ABFE AC73 B6D4 75F3 4DA6 32BE

To claim this, I am signing this object:

@amosshapira
amosshapira / lambda.py
Last active December 8, 2016 06:22
Example for setting S3 bucket "ExpiredObjectDeleteMarker" automatically from CloudFormation
# Extracted from the CloudFormation template.json below with:
# jq -r .Resources.RemoveExpiredObjectDeleteMarkerFunction.Properties.Code.ZipFile < template.json
import uuid
import httplib
import urlparse
import json
import boto3
import botocore
import traceback
@amosshapira
amosshapira / zipfilestring.py
Created November 28, 2016 03:30
sample code for generating a zip file in memory using Python. Useful for AWS Lambda Python
import StringIO
import zipfile
import os
import os.path
def append_requests_module_code(zf):
requests_path = os.path.dirname(os.path.realpath(requests.__file__))
for root, dirs, files in os.walk(requests_path):
ziproot = os.path.join('requests', root[len(requests_path)+1:])
for fn in files:
@amosshapira
amosshapira / list-cloudformation-stacks.sh
Last active October 19, 2016 04:43
List existing CloudFormation stacks
#!/bin/sh
# list cloudfomation stacks, filter out deleted stacks,
# print only stack names and status, align in nice columns
aws cloudformation list-stacks \
--query 'StackSummaries[?StackStatus!=`DELETE_COMPLETE`].[StackName, StackStatus]' \
--output text | \
column -t
@amosshapira
amosshapira / cloudformation-aws-elasticsearch.json
Created September 27, 2016 04:39 — forked from mirajavora/cloudformation-aws-elasticsearch.json
Elastic Search AWS Cloudformation Script
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Creates auto scaling Elastic Search Cluster",
"Parameters" : {
"InstanceType" : {
"Description" : "Elastic Search node instance type",
"Type" : "String",
"Default" : "t2.small",
@amosshapira
amosshapira / find-unused-amis
Last active March 22, 2024 16:00
Find self-owned AMI's which are not used by any instances or launch configurations in a region
#!/bin/bash
# Find self-owned AMI's which are not used by any instances or launch configurations in the default region.
comm -23 \
<(aws ec2 describe-images --owner self --query 'Images[].[ImageId]' --output text | sort) \
<((aws ec2 describe-instances --query 'Reservations[].Instances[].[ImageId]' --output text;
aws autoscaling describe-launch-configurations --query 'LaunchConfigurations[].[ImageId]' --output text) | sort -u)