Skip to content

Instantly share code, notes, and snippets.

View nmagee's full-sized avatar

Neal Magee nmagee

View GitHub Profile
@nmagee
nmagee / simple-sns-publish.py
Created November 12, 2020 16:57
A demo of publishing an SNS message. Update with the ARN of your own SNS Topic.
#!/usr/bin/env python3
import json
import boto3
import datetime
sns = boto3.client('sns')
response = sns.publish(
TopicArn="arn:aws:sns:us-east-1:555566667777:simple-topic",
@nmagee
nmagee / index.html
Last active November 11, 2021 21:22
PA Submission form for S3+CloudFront
<!DOCTYPE html>
<html>
<head>
<title>CS4740 - CloudFront+SNS+Lambda+SNS+Dynamo Application</title>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.780.0.min.js"></script>
<link href="https://getbootstrap.com/docs/4.5/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
</head>
<body>
<script type="text/javascript">
@nmagee
nmagee / describe-instances.py
Created October 1, 2020 17:09
Python3 snippet to iterate out InstanceIds in EC2.
import boto3
ec2 = boto3.client('ec2')
response = ec2.describe_instances()
for r in response['Reservations']:
for i in r['Instances']:
print(i['InstanceId'])
@nmagee
nmagee / apache2-remote-bootstrap
Created September 24, 2020 14:58
Fetches a remote shell script to execute for bootstrapping
#!/bin/bash
curl -O https://gist.githubusercontent.com/nmagee/5636d0355d48998f91502dd811a7401c/raw/6833433672715308fff57f86792d1246ba5fe677/apache2-bootstrap.sh
/bin/bash apache2-bootstrap.sh
@nmagee
nmagee / apache2-bootstrap.sh
Created September 24, 2020 14:53
Bootstraps Amazon Linux 2 with apache2 daemon
#!/bin/bash
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
@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'])