Skip to content

Instantly share code, notes, and snippets.

@coingraham
coingraham / aws_client_vpc_endpoint_setup_notes.md
Created June 15, 2022 02:54 — forked from mlimotte/aws_client_vpc_endpoint_setup_notes.md
AWS Client VPN Endpoint Setup tips and checklist

Overview

We have remote developers who occassionally need access to AWS servers QA and Staging databases (RDS mysql instances). The AWS servers (EC2, fargate) are in a private VPC. The RDS databases are in different VPCs, they have the "publicly accessible" attribute set, which means they get a pubilc DNS, but only a handful or IPs are whitelisted for that access; developers should get access over a VPN.

This is summarized as:

laptop --ClientVPN--> VPC _A_ --VPC Peer--> RDS in VPC _B_

I choose the Cliet VPN Endpoint so that AWS would manage the remote side of the tunnel. I choose Viscosity (on a Mac) as our VPN client because it's easy to use and support split-dns and split-routing. It's affordable, but not free. Split DNS is important so that Amazon hostnames can be resolved to their internal IP addresses. Split routing is important so that only the AWS destined traffic goes over the VPC tunnel and other internet traffic can go direct to internet.

@coingraham
coingraham / README.md
Created January 16, 2020 15:52 — forked from nitrocode/README.md
Cloud custodian iam policy in terraform

CloudCustodian IAM Policy

Extracts perms from cloud-custodian repo, sanitizes extracted data, and transforms into terraform

Dependency is ripgrep and git which can be installed using brew

brew install rg git

The code will

@coingraham
coingraham / boto3_handleexceptions.py
Created August 27, 2019 16:29 — forked from stewmi/boto3_handleexceptions.py
Handling Exceptions in Boto3
import boto3
from botocore.exceptions import ClientError
try:
iam = boto3.client('iam')
user = iam.create_user(UserName='fred')
print("Created user: %s" % user)
except ClientError as e:
if e.response['Error']['Code'] == 'EntityAlreadyExists':
print("User already exists")
Import-Module ADFS
Add-ADFSRelyingPartyTrust -Name "Amazon Web Services & AD Groups" -MetadataURL "https://signin.aws.amazon.com/static/saml-metadata.xml" -MonitoringEnabled:$true -AutoUpdateEnabled:$true
$ruleSet = New-AdfsClaimRuleSet -ClaimRuleFile ((pwd).Path + "\claims-AD-Groups.txt")
$authSet = New-AdfsClaimRuleSet -ClaimRuleFile ((pwd).Path + "\auth.txt")
Set-AdfsRelyingPartyTrust -TargetName "Amazon Web Services & AD Groups" -IssuanceTransformRules $ruleSet.ClaimRulesString -IssuanceAuthorizationRules $authSet.ClaimRulesString
@coingraham
coingraham / spark_s3_dataframe_gdelt.py
Created June 4, 2018 14:46 — forked from jakechen/spark_s3_dataframe_gdelt.py
Creating PySpark DataFrame from CSV in AWS S3 in EMR
# Example uses GDELT dataset found here: https://aws.amazon.com/public-datasets/gdelt/
# Column headers found here: http://gdeltproject.org/data/lookups/CSV.header.dailyupdates.txt
# Load RDD
lines = sc.textFile("s3://gdelt-open-data/events/2016*") # Loads 73,385,698 records from 2016
# Split lines into columns; change split() argument depending on deliminiter e.g. '\t'
parts = lines.map(lambda l: l.split('\t'))
# Convert RDD into DataFrame
from urllib import urlopen
html = urlopen("http://gdeltproject.org/data/lookups/CSV.header.dailyupdates.txt").read().rstrip()
@coingraham
coingraham / delete_snapshots.py
Last active August 14, 2017 22:26 — forked from kjoconnor/delete_snapshots.py
boto script to delete snapshots matching a filter and older than X days
import sys
import boto3
from botocore.exceptions import ClientError
from datetime import datetime, timedelta
import time
import pytz
profile = "my_profile"
region = "us-west-2"
dry_run = True
@coingraham
coingraham / connectivity.sh
Created March 16, 2017 19:03 — forked from mlconnor/connectivity.sh
Diagnose Connectivity
#set -o xtrace
echo "please copy the output of this script and send it to the network team so they can diagnose your issue"
DESTINATION=destination.foo.com
PORT=8089
echo "Dumping local network data"
ifconfig
# get the routing table
@coingraham
coingraham / website-checker.sh
Last active March 13, 2017 21:44 — forked from dominic-p/website-checker.sh
This is a shell script to check a provided list of URLs to see if the websites are working or not. It was based on the answers provided to this question: http://stackoverflow.com/q/21391776/931860
#!/bin/sh
# ---- website-checker.sh ----
# Pings a list of websites using cURL to see if they are up and
# there are no errors. If there are problems, we send an email using mailx
# to let ourselves know about the problem.
################################################################################
# This is a path to a plain text list of URLs to check, one per line
# Make sure this uses proper unix newline characters or you will get 400 Bad Request errors
# when you try to curl the URLs