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 / aws-jq-simple-requests.sh
Last active October 2, 2018 20:07
Use JQ to parse AWS CLI requests
#!/bin/bash
# Display the EIPs associated with all of your instances:
aws ec2 describe-instances \
| jq -r .Reservations[].Instances[].PublicIpAddress
# Display the EIP attached to a specific EC2 instance:
aws ec2 describe-instances --instance-ids i-1a2b3c4d5e6f7g8h9i \
| jq -r .Reservations[0].Instances[0].PublicIpAddress
@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',
@nmagee
nmagee / retrieve-ec2-instance-types.sh
Last active November 25, 2019 12:26
Query the AWS Pricing API to get all currently available EC2 instance types
#!/bin/bash
curl https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.json | jq -r '.products[].attributes["instanceType"]' | sort -u | grep '\.'
{
"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