Skip to content

Instantly share code, notes, and snippets.

View ffturan's full-sized avatar

Fehmi F Turan ffturan

View GitHub Profile
#!/usr/bin/env python3
import boto3
import sys
from botocore.exceptions import ClientError
def check_args():
if len(sys.argv) < 4:
print(f'Usage: {sys.argv[0]} profile-name region-name bucket-name [folder-name]')
exit()
@ffturan
ffturan / create-main-athena-table.sql
Created October 22, 2020 01:06
Analyze AWS VPC flow logs with Athena
# Export log format:
# ${version} ${account-id} ${interface-id} ${srcaddr} ${dstaddr} ${srcport} ${dstport} ${protocol} ${packets} ${bytes} ${start} ${end} ${action} ${log-status} ${vpc-id} ${subnet-id} ${instance-id} ${tcp-flags} ${type} ${pkt-srcaddr} ${pkt-dstaddr
CREATE EXTERNAL TABLE IF NOT EXISTS vpc_flow_logs_myawsaccount (
version int,
account string,
interfaceid string,
sourceaddress string,
destinationaddress string,
sourceport int,
@ffturan
ffturan / ec2-instance-tagger.py
Last active October 21, 2020 16:48
Use an existing tag on AWS EC2 instance/s to add/delete new/old tags
#!/usr/bin/env python3
#
# Use an existing tag on AWS EC2 instance/s to add/delete new/old tags.
#
# Usage: ./ec2-instance-tagger.py <aws-profile> <aws-region> <existing-tag-key> <existing-tag-value> <target-tag-key> <target-tag-value> <action>
#
# I've 3 EC2 instances already tagged with Temp:True , adding new tag Zone:2
# ./ec2-instance-tagger.py myawsprofile us-east-1 Temp True Zone 2 add
# Expected output:
@ffturan
ffturan / ec2-snapshot-usage.py
Created October 21, 2020 15:07
Lists number of AWS snapshots associated and not associated with an AMI
#!/usr/bin/env python3
# ~~~~~~~~~~
# Lists number of snapshots associated and not associated with an AMI
# Requires : AWS PROFILE/REGION/ACCOUNT ID
#
# Usage: ./ec2_snapshot_usage.py <aws-profile> <aws-region> <aws-account-id>
# Usage: ./ec2_snapshot_usage.py myawsprofile us-east-1 111111111111
#
# Expected Output:
@ffturan
ffturan / fix-aws-lambda-tz.py
Last active July 21, 2023 07:18
Fix AWS lambda function timezone [python]
import json
import os
import time
#
vLocalTimeZone='US/Eastern'
#
def lambda_handler(event, context):
# Run time in UTC