Skip to content

Instantly share code, notes, and snippets.

View nmagee's full-sized avatar

Neal Magee nmagee

View GitHub Profile
@nmagee
nmagee / presign-s3.py
Last active September 15, 2020 19:28
Presign a URL in S3 using boto3
#!/usr/local/bin/python3
# To use this snippet:
# Create a bucket and upload a private file into it beforehand.
# To make the private file shareable for a fixed number of seconds
# you can "presign" the URL, which creates an expiring hashed URL.
# You can then distribute that URL to other systems or coleagues.
import boto3
@nmagee
nmagee / bootstrap.sh
Created August 21, 2020 15:13
Bootstraps an Amazon Linux EC2 instance with some basic tools
#!/bin/bash
/usr/bin/yum update -y
/bin/amazon-linux-extras install -y epel
/usr/bin/yum install -y git python3 python3-dev python3-pip nfs-utils
/bin/pip3 install boto3 pandas requests
@nmagee
nmagee / create-amis.py
Last active December 12, 2019 17:55
Lambda function for creating AMIs of your entire EC2 region.
# Written for AWS Lambda, for the Python 3.6 runtime.
import json
import boto3
import datetime
## Be sure to set account number on line 57.
## Set DRY RUN value - for testing or running.
dryrun = False
@nmagee
nmagee / assume-role.py
Created March 1, 2019 14:44
Get temporary AWS Credentials for external users by assuming a defined IAM Role
#!/usr/local/bin/python
import boto3
import json
# The calls to AWS STS AssumeRole must be signed with the access key ID
# and secret access key of an existing IAM user or by using existing temporary
# credentials such as those from antoher role.
# Python SDK documentation:
# http://boto3.readthedocs.io/en/latest/reference/services/sts.html#client
@nmagee
nmagee / evaluate-compliance.py
Last active October 31, 2018 19:28
Lambda function for Config service. Watches an EC2 security group for changes and evaluates.
import json
import boto3
from datetime import datetime
# Use as a starter/stub -- can and should be modified for production
FORMAT = '%Y%m%d-%H:%M:%S'
now = datetime.now().strftime(FORMAT)
def lambda_handler(event, context):
invoking_event = json.loads(event['invokingEvent'])
#!/usr/local/bin/python3
# A dumb/simple script to retrieve the value of a SecretsManager secret
import boto3
import base64
from botocore.exceptions import ClientError
def get_secret():
@nmagee
nmagee / dcos-setup.txt
Created September 11, 2018 15:13
Prepares a CentOS cluster for installation of DC/OS.
# DC/OS Prep for Install
#
# The following playbooks should be run, in order, to prep a CentOS cluster for installation of DC/OS.
# This list is based on the software prerequisites published by Mesosphere:
# https://docs.mesosphere.com/1.11/installing/production/system-requirements/
- 1-add-ansible-user.playbook
- 2-install-basics.playbook
- 3-add-nogroup.playbook
- 4-docker.playbook
#!/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
#!/bin/bash
# Transfers a single file via script.
# Note the optional --encrypt flag.
set -e
globus=`which globus`
srce=c4d80096-7612-11e7-8b5e-22000b9923ef
dest=c4d80096-7612-11e7-8b5e-22000b9923ed
@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