Skip to content

Instantly share code, notes, and snippets.

@monkut
monkut / lambdaenvars.py
Last active Jun 3, 2021
Command-line script to get/set environment variables and list existing aws lambda functions
View lambdaenvars.py
"""
Get/Set lambda environment variables
"""
import os
import pprint
from pathlib import Path
from typing import Tuple, List
from enum import Enum
import boto3
@monkut
monkut / connectmidicontroller.py
Created Jan 4, 2021
auto connect midi controller script for fluidsynth, rasbian
View connectmidicontroller.py
from time import sleep
from subprocess import check_output, CalledProcessError
controller_identifier = 'microKEY2'
configured = False
while True:
aconnect_list_command = ('aconnect', '-o')
output_bytes = check_output(aconnect_list_command)
output_str = output_bytes.decode('utf8')
controller_attached = False
@monkut
monkut / autostartsynth.sh
Created Jan 4, 2021
an fluidsynth autostart script for raspberrypi
View autostartsynth.sh
#! /bin/sh
# rasbian
# add the following line to /etc/rc.local above the "exit 0" line to start on boot
# /home/pi/autostartsynth.sh &
killall fluidsynth
# set sound
export DESIRED_SOUNDFONT=/usr/share/sounds/sf2/FluidR3_GM.sf2
# start fluidsynth with desired sound
@monkut
monkut / iterate_s3_csv.py
Created Nov 28, 2020
iterate a csv file in S3 from memory
View iterate_s3_csv.py
import boto3
S3_CLIENT = boto3.client("s3")
def iterate_s3_csv(bucket: str, key: str) -> Generator:
with BytesIO() as bytesin:
S3_CLIENT.download_fileobj(bucket, key, bytesin)
bytesin.seek(0)
stringin = StringIO(bytesin.read().decode("utf8"))
@monkut
monkut / lambdaenvars.py
Created Nov 17, 2020
cli tool to get/set aws lambda environment variables
View lambdaenvars.py
"""
Get/Set lambda environment variables
"""
import os
import pprint
from pathlib import Path
from typing import Tuple, List
from enum import Enum
import boto3
@monkut
monkut / update_awslambda_envars.bash
Created Jan 11, 2020
update aws lambda environment variables via awscli and jq
View update_awslambda_envars.bash
# the `update-function-configuration` overwrites the existing set envars.
# In order to *ADD* variables we need to read the existing envars and add to that.
# This command uses `jq` to read and transform the json result to an envar then update the lambda configuration
# create the updated envar set
export YOUR_FUNCTION_NAME={populate this}
export UPDATED_ENVIRONMNET_VARIABLES=$(aws lambda get-function-configuration --function-name ${YOUR_FUNCTION_NAME} | \
jq --compact-output ".Environment + {\"Variables\": (.Environment.Variables + {\"NEW_ENVAR_NAME\": \"NEW_ENVAR_VALUE\"})}")
# check
View boto3_secretsmanager_usage_example.py
import json
import boto3
secretsmgr_endpoint_url = 'http://localhost:4584'
SM_CLIENT = boto3.client('secretsmanager', endpoint_url=secretsmgr_endpoint_url)
# Set Secret
sample_secret_id = 'some:id:2'
secret_data = json.dumps({'key1': 'value1', 'key2': 'value2'})
@monkut
monkut / boto3_service_endpoints.py
Created Sep 20, 2019
boto3 defined default service endpoints definition for use with localstack
View boto3_service_endpoints.py
import os
AWS_REGION = os.getenv('AWS_DEFAULT_REGION', 'ap-northeast-1')
DEFAULT_S3_SERVICE_ENDPOINT = f'https://s3.{AWS_REGION}.amazonaws.com'
DEFAULT_SQS_SERVICE_ENDPOINT = f'https://sqs.{AWS_REGION}.amazonaws.com'
DEFAULT_SNS_SERVICE_ENDPOINT = f'https://sns.{AWS_REGION}.amazonaws.com'
AWS_SERVICE_ENDPOINTS = {
's3': os.getenv('S3_SERVICE_ENDPOINT', DEFAULT_S3_SERVICE_ENDPOINT),
@monkut
monkut / mediainfo_xml_parse.py
Created Sep 20, 2019
a python parser for `mediainfo` output
View mediainfo_xml_parse.py
import json
import subprocess
from xml.etree import ElementTree
import boto3
from . import settings
S3 = boto3.client(
's3',
endpoint_url=settings.AWS_SERVICE_ENDPOINTS['s3'],
)
@monkut
monkut / tilemill_ubuntu18.04_install.md
Last active Sep 11, 2019
install tilemill in ubuntu 18.04
View tilemill_ubuntu18.04_install.md

install libs

sudo apt-get install autoconf automake libtool curl make g++ unzip -y

clone and install protobuf

cd ~