Skip to content

Instantly share code, notes, and snippets.

@coingraham
coingraham / assume.sh
Created October 24, 2019 16:42
Bash Assume AWS Role
#!/bin/bash
set -ve
# get the deploy role and region from the settings file
deployRole="role_name"
deployRegion="region"
# assume the deploy role
if [ -n "$deployRole" ]; then
assumedRoleDetails=$(aws sts assume-role --role-arn $deployRole --role-session-name ui-deploy)
@coingraham
coingraham / glue_sql.py
Created October 22, 2019 18:21
Glue PySpark Command to run SQL
pre_query = "truncate table target_table"
post_query= "begin;delete from target_table using stage_table where stage_table.id = target_table.id ; insert into target_table select * from stage_table; drop table stage_table; end;"
connection_options_redshift = {
"preactions": pre_query,
"dbtable": "stage_table",
"database": "redshiftdb",
"postactions":post_query
}
@coingraham
coingraham / HCL
Created September 26, 2019 20:44
Terraform Default Tags
variable "default_tags" {
type = "map"
default = {}
}
default_tags = {
foo = "bar"
}
...
@coingraham
coingraham / s3_comparison.py
Created September 24, 2019 15:04
Pandas Reading from S3 Comparison
import boto3
import pandas as pd
import time
import io
start = time.time()
s3 = boto3.client('s3')
s3_resource = boto3.resource('s3')
@coingraham
coingraham / s3_read_options_interesting.py
Created September 19, 2019 20:00
Comparing pandas read of Parquet, CSV and S3 Select of CSV
#!/usr/bin/python3
import boto3
import pandas as pd
import time
import io
s3 = boto3.client('s3')
s3_resource = boto3.resource('s3')
def s3_select(bucket, key, statement):
s3_select_results = s3.select_object_content(
Bucket=bucket,
Key=key,
Expression=statement,
ExpressionType='SQL',
InputSerialization={'CSV': {"FileHeaderInfo": "Use"}},
OutputSerialization={'JSON': {}},
)
@coingraham
coingraham / glue_shell_installer.py
Created September 17, 2019 13:36
Glue Shell Installer
import os
import site
from setuptools.command import easy_install
install_path = os.environ['GLUE_INSTALLATION']
easy_install.main( ["--install-dir", install_path, "<library-name>"] )
reload(site)
import <installed library>
@coingraham
coingraham / setup.sh
Last active November 20, 2023 20:08
Setup My Mac
# Install Chrome
# Update browser default settings
# Install VSCode
# Install iTerm2
# Install PyCharm
# Install Homebrew
@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")
@coingraham
coingraham / permissions.sql
Created January 29, 2019 15:27
Glue RDS Connection Permissions
// The user that will execute the crawl needs:
execute ,SELECT, SHOW VIEW ON `database`.*