Skip to content

Instantly share code, notes, and snippets.

@davidshtian
davidshtian / s3-to-efs.py
Created March 18, 2021 06:20
AWS Lambda Download S3 File to Mounted EFS
import json
import os
import boto3
import botocore
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
s3 = boto3.client('s3')
@davidshtian
davidshtian / aws_glue_partition_nums.py
Created October 10, 2020 09:08
Get the partition numbers of all AWS Glue databases and tables.
import boto3
from prettytable import PrettyTable
res = PrettyTable()
res.field_names = ["Database", "Table", "Partition Num"]
glue = boto3.client('glue')
dbs = glue.get_databases()['DatabaseList']
@davidshtian
davidshtian / aws-mfa-cli.sh
Last active August 28, 2020 14:20
aws-mfa-cli
#!/bin/bash
token=`aws sts get-session-token --serial-number $1 --token-code $2 --profile $3`
ak=`echo $token | jq '.Credentials.AccessKeyId' | tr -d '"'`
sk=`echo $token | jq '.Credentials.SecretAccessKey' | tr -d '"'`
st=`echo $token | jq '.Credentials.SessionToken' | tr -d '"'`
aws configure set aws_access_key_id $ak --profile mfa
aws configure set aws_secret_access_key $sk --profile mfa
@davidshtian
davidshtian / print_aws_ec2_az.py
Last active August 28, 2020 14:21
print_aws_ec2_az
import boto3
ec2 = boto3.client('ec2')
regions_res = ec2.describe_regions()
regions = [region['RegionName'] for region in regions_res['Regions']]
for region in regions:
region_list = [region]
ec2 = boto3.client('ec2', region_name=region)