Skip to content

Instantly share code, notes, and snippets.

View reecestart's full-sized avatar
💻

Reece reecestart

💻
View GitHub Profile
@reecestart
reecestart / create-athena-table-for-csvs.sql
Created May 10, 2017 20:58
Create Athena Table for CSVs
CREATE EXTERNAL TABLE IF NOT EXISTS athenadatabaseforcsvs.athenatableforcsvs (
aws_account_id string,
name string,
email string,
status string,
category string,
description string,
refreshed string,
processed string,
flagged string,
@reecestart
reecestart / select-rows-with-status-that-have-changed.sql
Created May 10, 2017 21:02
Select Rows with Status that has Changed
SELECT a.aws_account_id, a.name, a.description, a.refreshed, a.status
FROM
athenatableforcsvs AS a
INNER JOIN
athenatableforcsvs AS b
ON a.aws_account_id = b.aws_account_id AND a.description = b.description
WHERE
a.status <> b.status
GROUP BY a.aws_account_id, a.name, a.description, a.refreshed, a.status
ORDER BY 1, 2, 3, 4, 5;
@reecestart
reecestart / listRunningEC2InstancesWithTags.ps1
Created January 9, 2018 04:32
cmdlet that can list all running ec2 instances with tags in table format
$Regions = Get-EC2Region
$Regions = $Regions.RegionName
$RunningInstances = @()
foreach ($Region in $Regions)
{
$EC2Instances = Get-EC2Instance -Region $Region
foreach ($EC2Instance in $EC2Instances)
{
if ($EC2Instance.Instances.state.name.value -eq 'running')
{
@reecestart
reecestart / getVirtualCoresForEC2InstanceTypes.ps1
Created January 10, 2018 05:44
Programmatically get the # of virtual cores for an EC2 instance type to figure out licensing costs
# Programmatically get the # of virtual cores for an EC2 instance type to figure out licensing costs
# https://aws.amazon.com/ec2/virtualcores/
$Region = 'us-east-1'
$ServiceCode = 'AmazonEC2'
$Products = Get-plsproduct -ServiceCode $ServiceCode -Filter @{Type="TERM_MATCH";Field="productFamily";Value="Compute Instance"},@{Type="TERM_MATCH";Field="location";Value="Asia Pacific (Sydney)"} -Region $Region
$VirtualCoresByAmazonEC2InstanceType = @()
@reecestart
reecestart / create-account.py
Created January 24, 2018 03:19
Create AWS Account with Python using Organizations
import time
import boto3
import pprint
# setup pprint
pp = pprint.PrettyPrinter(indent=1)
# define the connection
client = boto3.client('organizations')
@reecestart
reecestart / test-s3-version-sync.sh
Created February 1, 2018 01:48
Testing the effect of S3 Sync on an object with multiple Versions
#!/bin/bash
# Tested using bash version 3.2.57
echo Source Test Bucket?
read sourcetestbucketname
sourcetestbucket="s3://$sourcetestbucketname"
aws s3 mb $sourcetestbucket
echo Destination Test Bucket?
@reecestart
reecestart / get-RI-utilization.sh
Created February 14, 2018 04:12
Bash script to get the RI Utilization given a start and end date, granularity either daily or monthly
#!/usr/bin/env
# To check RI Utilization
echo "What is your Start Date for checking RI Utilization? (YYYY-MM-DD)"
read startDate
startDateString="Start=$startDate"
echo "What is your End Date for checking RI Utilization? (YYYY-MM-DD)"
read endDate
endDateString="End=$endDate"
@reecestart
reecestart / check-ASG-SLRs.ps1
Created May 31, 2018 05:27
Checks all ASG's to see if they were created with a Service Linked Role and if not, lists username of who created the ASG
cls
$ASGs = Get-ASAutoScalingGroup
$ASGsWithoutSLR = @()
foreach ($ASG in $ASGs)
{
if ($ASG.ServiceLinkedRoleARN -eq $null)
{
$ASGsWithoutSLR += $ASG
@reecestart
reecestart / t2UnlimitedLaunchTemplateWithASG.json
Created June 15, 2018 03:03
Creates a Launch Template and Auto Scaling Group with two t2.micro T2 Unlimited EC2 Instances
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "T2 Unlimited Launch Template",
"Outputs": {
"LaunchTemplate": {
"Value": {
"Ref": "TestLaunchTemplate"
}
}
},
@reecestart
reecestart / describe-rds-private-ips.py
Last active April 30, 2024 17:40
Will print out RDS DB Instance DB Identifiers with their ENI and Private IP. Will only work if one SG is used per RDS DB (EDIT: Updated to work for DB Clusters e.g. Aurora Serverless)
import boto3
ec2_client = boto3.client('ec2')
rds_client = boto3.client('rds')
rdsNetworkInterfaces = ec2_client.describe_network_interfaces(
Filters=[
{
'Name': 'attachment.instance-owner-id',
'Values': [