Skip to content

Instantly share code, notes, and snippets.

View nmagee's full-sized avatar

Neal Magee nmagee

View GitHub Profile
@nmagee
nmagee / copy-ami.sh
Created April 12, 2015 17:35
Copy AMI to new Region
#!/bin/sh
# This script creates a series of prompts to create an AMI of an EC2 instance from a few AWS profiles
# Comes with a fixed US-East-1 to US-West-2 migration path. Modify accordingly for your own needs.
# 09.05.2014 Neal Magee
set -e
clear
echo ""
read -p " What AWS profile does this AMI belong to? (Enter 'default' to use that profile): " profile
@nmagee
nmagee / create-ami.sh
Created April 12, 2015 17:36
Create an EC2 AMI using your InstanceId
#!/bin/sh
# This script creates a series of prompts to create an AMI of an EC2 instance from a few AWS profiles
# Note that the YYYYmmdd- is added to the name of the AMI automatically
set -e
clear
# Check for AWS CLI tools
type aws >/dev/null 2>&1 || { echo >&2 "\n\n I require the AWS CLI but it's not installed. Please visit http://aws.amazon.com/cli/ and install it. Aborting.\n"; exit 1; }
@nmagee
nmagee / sign-s3-url.py
Created October 21, 2015 19:31
Sign S3 URL
#!/usr/bin/env python
# http://boto3.readthedocs.org/en/latest/reference/services/rds.html
import boto3
import sys, getopt
bucket = None
file_path = None
timeout_seconds = 3600
@nmagee
nmagee / boto3-error-example
Last active July 18, 2017 14:08
A simple example of how to handle boto3 errors using botocore
import boto3
import botocore
import errorsns # A custom SNS handler
def check_queue():
client = boto3.client('sqs', region_name='us-east-1')
req = client.receive_message(
QueueUrl='https://sqs.us-east-1.amazonaws.com/123456789012/my-queue',
MessageAttributeNames=[
'JobID',
{
"success": {
"total": 1
},
"contents": {
"quotes": [
{
"quote": "When it comes to winning, you need the skill and the will.",
"length": "58",
"author": "Frank Tyger",
@nmagee
nmagee / sync-up.sh
Created November 6, 2017 19:19
Synchronize a local folder up to an S3 bucket
#!/bin/bash
bucket='YOUR-BUCKET-NAME'
dir='/your/local/directory/'
aws s3 sync $dir s3://$bucket
# If you want the bucket to match the local directory exactly, including any files
# you may delete at a later point, add --delete after sync
#
@nmagee
nmagee / sync-down.sh
Created November 6, 2017 19:21
Synchronize an S3 bucket with a local folder
#!/bin/bash
bucket='YOUR-BUCKET-NAME'
dir='/your/local/directory/'
aws s3 sync s3://$bucket/ $dir
# If you want the bucket to match the local directory exactly, including any files
# you may delete at a later point, add --delete after sync
#
@nmagee
nmagee / start-instances.sh
Created November 7, 2017 16:37
Start one or more EC2 instances. Run this on your local workstation.
#!/bin/bash
# This can be one or more EC2 instance IDs, separated by a space. No commas.
instanceIds=''
aws ec2 start-instances --instance-ids $instanceIds
@nmagee
nmagee / stop-instances.sh
Created November 7, 2017 16:37
Stop one or more EC2 instances. Run this on your local workstation.
#!/bin/bash
# This can be one or more EC2 instance IDs, separated by a space. No commas.
instanceIds=''
aws ec2 stop-instances --instance-ids $instanceIds
#!/bin/bash
# Transfers a directory, recurisvely.
# Note the optional --encrypt flag.
set -e
globus=`which globus`
srce=c4d80096-7612-11e7-8b5e-22000b9923ef
dest=c4d80096-7612-11e7-8b5e-22000b9923ed