Skip to content

Instantly share code, notes, and snippets.

View daniel-woods's full-sized avatar

Daniel Woods daniel-woods

  • Amazon
  • Dublin, Ireland
View GitHub Profile
@daniel-woods
daniel-woods / aws_polling_threading.py
Created April 22, 2019 12:27
Poll AWS APIs faster using multithreading
#!/usr/bin/env python
# Multi threading way to query AWS regional APIs.
# A lot faster than synchronously polling each region one-after-another.
import boto3
import threading
from time import sleep
logs = []
@daniel-woods
daniel-woods / calculate_subset.py
Created April 11, 2019 19:33
Calculate the sum of the largest continuous integers in an array
def calculate_subs(_list):
totals = []
index = 0
first_val = True
for i in _list:
if first_val:
totals.append(i)
first_val = False
else:
if i - prev == 1:
@daniel-woods
daniel-woods / shift_list.py
Created April 11, 2019 19:31
Shifting an inputted list by an offset
def myfnc(l, n):
le = len(l)
return l[n % le::] + l[:n % le:]
def main():
input_list = [1, 2, 3, 4, 5]
shift_rotate = 2
x = myfnc(input_list, shift_rotate)
print(x)
@daniel-woods
daniel-woods / roman_to_arabic.py
Created April 11, 2019 19:28
Converting Roman Numerals into Arabic numbers
def convert(numeral):
romans = {
"I": 1,
"V": 5,
"X": 10,
"L": 50,
"C": 100,
"D": 500,
"M": 1000
}
@daniel-woods
daniel-woods / lambda_function.py
Last active April 11, 2019 16:58
Lambda function that uses the pathParameters.proxy to determine the action taken. (EC2 Start/Stop/Reboot)
import boto3
import json
# Add any instance IDs to the list instances
# instances = ["i-xxxxxxx", "i-yyyyyyy", "i-zzzzzzz"]
instances = ["i-xxxxxxx"]
def lambda_handler(event, context):
ec2_client = boto3.client("ec2")
@daniel-woods
daniel-woods / helloworld.go
Created March 10, 2019 19:10
A "Hello World" function written in Golang for demonstration using AWS Lambda
package main
import "github.com/aws/aws-lambda-go/lambda"
func handleRequest () (string, error) {
return "Hello from Go!", nil
}
func main() {
lambda.Start(handleRequest)
}
#!/usr/bin/env python
import boto3
import time
sns = boto3.client("sns")
arn = "TOPIC_ARN"
count = 0
while True:
@daniel-woods
daniel-woods / sns_lambda_teams_webhook.py
Last active September 29, 2018 02:40
Use a Webhook to send a message to a Microsoft Teams channel using Connectors/Incoming Webhook
#!/usr/bin/python3
# https://gist.github.com/daniel-woods
# Use a Webhook to send a message to a Microsoft Teams channel using Connectors/Incoming Webhook
import json
from urllib2 import urlopen, HTTPError, Request
def post_message(url, data):
req = Request(url, data)
@daniel-woods
daniel-woods / cognito_check_if_number_in_use.py
Created September 9, 2018 10:18
Check if a number exists in a Cognito User Pool
#!/usr/bin/python
import boto3
import json
# Query Parameters:
# Phone Number we need to look up
phone_num = "+xxxxxxxxxxxxx"
# In which User Pool?
@daniel-woods
daniel-woods / amznssh.sh
Created September 9, 2018 10:12
Use the AWSCLI to parse the Public IP from a describe-instances call to connect via SSH.
#!/bin/bash
# Default user uses different names, depending on OS.
# Amazon Linux = "ec2-user"
# Ubuntu = "ubuntu"
remote_user="ec2-user"
pem="/home/.ssh/YOUR_PRIVATE_KEY"
port=22