Skip to content

Instantly share code, notes, and snippets.

{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "AWS CloudFormation sample template that contains a single Lambda function behind an API Gateway",
"Resources": {
"GreetingLambda": {
"Type": "AWS::Lambda::Function",
"Properties": {
@iotspace
iotspace / handler_fieldstorage.py
Created December 8, 2020 06:23 — forked from davidejones/handler_fieldstorage.py
aws lambda parsing multipart form with python3
from cgi import FieldStorage
from io import BytesIO
def parse_into_field_storage(fp, ctype, clength):
fs = FieldStorage(
fp=fp,
environ={'REQUEST_METHOD': 'POST'},
headers={
'content-type': ctype,
@iotspace
iotspace / Makefile
Created December 25, 2020 02:51 — forked from mpneuried/Makefile
Simple Makefile to build, run, tag and publish a docker containier to AWS-ECR
# import config.
# You can change the default config with `make cnf="config_special.env" build`
cnf ?= config.env
include $(cnf)
export $(shell sed 's/=.*//' $(cnf))
# import deploy config
# You can change the default deploy config with `make cnf="deploy_special.env" release`
dpl ?= deploy.env
include $(dpl)
@iotspace
iotspace / delete-vpc.sh
Created December 25, 2020 10:26 — forked from cjp/delete-vpc.sh
Delete AWS VPC including dependencies
#!/bin/sh
#
# Delete a VPC and its dependencies
if [ -z "$1" ] then
echo "usage: $0 <vpcid>"
exit 64
fi
vpcid="$1"
@iotspace
iotspace / LambdaBase.py
Created January 17, 2021 10:50 — forked from benkehoe/LambdaBase.py
Code pattern for implementing class-based AWS Lambda handlers in Python
"""Base class for implementing Lambda handlers as classes.
Used across multiple Lambda functions (included in each zip file).
Add additional features here common to all your Lambdas, like logging."""
class LambdaBase(object):
@classmethod
def get_handler(cls, *args, **kwargs):
def handler(event, context):
return cls(*args, **kwargs).handle(event, context)
return handler
@iotspace
iotspace / log.py
Created January 17, 2021 14:58 — forked from batzner/log.py
Python logging helper module
"""Helper module for logging.
Example Usage:
from log import get_logger, get_out_dir_of_logger
LOG = get_logger(__name__)
LOG.info('Logging to %s' % get_out_dir_of_logger(LOG))
"""
@iotspace
iotspace / combineS3Files.py
Created May 7, 2021 04:01 — forked from jasonrdsouza/combineS3Files.py
Python script to efficiently concatenate S3 files
'''
This script performs efficient concatenation of files stored in S3. Given a
folder, output location, and optional suffix, all files with the given suffix
will be concatenated into one file stored in the output location.
Concatenation is performed within S3 when possible, falling back to local
operations when necessary.
Run `python combineS3Files.py -h` for more info.
'''
@iotspace
iotspace / tar_examples.md
Created September 24, 2021 14:04 — forked from fakemelvynkim/tar_examples.md
tar examples

Tar Command Examples

options

-c  create
-x  extract
-v  verbose mode
-f  filename
-t  view content of archive file.
-j  bzip2

-z gzip

Get DynamoDB Local on Docker:

This will get it going:

$ docker run -itd --name dynamodb-local -p 8000:8000 rbekker87/dynamodb-local:latest

For Data Persistence:

@iotspace
iotspace / boto3-resource-profile.py
Created December 22, 2021 03:49 — forked from kheast/boto3-resource-profile.py
How to get boto3.resource to use a profile from credentials file
# To get boto3.resource to use a profile name, one must first
# setup a default session. The credentials provided during the
# session setup will be subsequently used by resource().
#
# See: https://github.com/boto/boto3/issues/21
# https://github.com/boto/boto3/pull/69
boto3.setup_default_session(profile_name=self.dpkg.profile_name)
self.ec2 = boto3.resource('ec2', region_name=self.dpkg.region_name)
filters = [{'Name': 'instance-state-name', 'Values': ['running']}]
for inst in self.ec2.instances.filter(Filters=filters):