Skip to content

Instantly share code, notes, and snippets.

View gbhorwood's full-sized avatar
💭
bitbucketing

grant horwood gbhorwood

💭
bitbucketing
View GitHub Profile
@gbhorwood
gbhorwood / nginx_geoip_nginx.conf
Created June 10, 2024 14:14
nginx geoip nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
@gbhorwood
gbhorwood / nginx_geoip_virtual_host.conf
Created June 10, 2024 14:13
nginx geoip virtual host
server {
server_name <domain name>;
root "<path to repository>";
index index.html index.htm index.php;
charset utf-8;
@gbhorwood
gbhorwood / put_to_s3.sh
Last active July 10, 2024 10:52
upload file to s3 bash script
#!/bin/bash
####
# Upload one file to configured S3 bucket
#
# 20240418 gbh
#
# Accepts the path to the file to upload as its only command-line argument. Uploads
# to the S3 bucket configured in the 'Configuration' block below.
#
@gbhorwood
gbhorwood / mailinglist.py
Created May 6, 2019 22:15
AWS lambda sample service source file
import json
import os
import sys
packages_path = os.path.join(os.path.split(__file__)[0], "packages")
sys.path.append(packages_path)
#----------------------------------
# Handler functions
@gbhorwood
gbhorwood / serverless.yml
Created May 6, 2019 22:05
AWS lambda simple serverless.yml
service: mailinglist # NOTE: update this with your service name
provider:
name: aws
runtime: python3.7
functions:
postSubscription:
handler: mailinglist.postSubscription
events:
@gbhorwood
gbhorwood / mungeBoto3Rds.py
Last active May 6, 2019 21:35
AWS lambda munge response from boto3 rds-data execute_sql
def mungeBoto3Rds(response):
# get a list of all the rows of data returned
records = response.get('sqlStatementResults')[0].get('resultFrame').get('records')
# get a list of keys so that element 0 of keys is the name of the column for
# the data in element 0 of records
keysList = list(map(lambda i: str(i.get('name')), response.get('sqlStatementResults')[0].get('resultFrame').get('resultSetMetadata').get('columnMetadata')))
# an empty list to hold our newly-munged data
@gbhorwood
gbhorwood / rdsdataexecutesqlsample.py
Created May 6, 2019 21:23
AWS lambda simple execute_sql() example, boto3
sql = "select * from registrations"
awsSecretStoreArn=getDotEnv("AWSSECRETSTOREARN")
dbClusterOrInstanceArn=getDotEnv("DBCLUSTERORINSTANCEARN")
database=getDotEnv("DATABASE")
# call data-api to execute sql
response = client.execute_sql(
awsSecretStoreArn=awsSecretStoreArn,
database=database,
@gbhorwood
gbhorwood / createboto3client.py
Created May 6, 2019 21:16
create a boto3 client
# import the boto modules
import botocore
import boto3
# get our aws credentials from our .env file
aws_access_key_id = str(getDotEnv("ACCESS_KEY_ID"))
aws_secret_access_key = str(getDotEnv("SECRET_ACCESS_KEY"))
region_name = str(getDotEnv("REGION_NAME"))
# create the client of type 'rds-data'
@gbhorwood
gbhorwood / getQueryStringElement.py
Created May 6, 2019 20:25
AWS Lambda function for getting values from query string
def getQueryStringElement(element, event, default=None):
if event is None:
return default
elif not('queryStringParameters' in event):
return default
if event['queryStringParameters'] is None:
return default
elif element in event['queryStringParameters']:
return event['queryStringParameters'].get(element)
@gbhorwood
gbhorwood / getDotEnv.py
Last active May 6, 2019 20:02
A short .env reader for lambda
def getDotEnv(element):
# import the dotenv functionality we need
from dotenv import load_dotenv, find_dotenv
# import the necessary commands we need to build a path to our .env file
from os.path import join, dirname
# create the path to .env file
dotenv_path = join(dirname(__file__), '.env')