Skip to content

Instantly share code, notes, and snippets.

View kennethphough's full-sized avatar

Kenneth P. Hough kennethphough

View GitHub Profile
@kennethphough
kennethphough / lambda_function.py
Created December 5, 2023 22:06
Python Lambda script for connecting to a RDS MySQL instance
import json
import pymysql
import os
def lambda_handler(event, context):
# Establish a connecto the the MySQL database
connection = pymysql.connect(host=os.environ['db_host'], user=os.environ['db_username'], password=os.environ['db_password'], database=os.environ['db_name'])
# Add a new user and print the updated user list
add_new_user(connection, 'JohnDoe', 'johndoe@example.com')
@kennethphough
kennethphough / lambda_function.py
Created December 6, 2023 02:21
Python-based Lambda function for sending SNS notifications to MS Teams
import os
import json
import requests
def lambda_handler(event, context):
msg = {'text': event['Records'][0]['Sns']['Message']}
headers = {'Content-Type': 'application/json'}
response = requests.post(os.environ['TEAMS_WEBHOOK_URL'], headers=headers, data=json.dumps(msg).encode('utf-8'))
return {
'statusCode': 200,