Skip to content

Instantly share code, notes, and snippets.

View ranman's full-sized avatar
🏠
Working from home

Randall Hunt ranman

🏠
Working from home
View GitHub Profile
export interface FunctionUrlRequest {
version: '2.0';
routeKey: '$default';
rawPath?: string;
rawQueryString?: string;
cookies?: string[];
headers: { [header: string]: string };
queryStringParameters: { [parameter: string]: string };
requestContext: {
accountId: string;
@ranman
ranman / lambda.md
Created October 9, 2020 00:05
lambda connection problem

AWS Serverless Network Connection Management

Problem Statement:

Serverless compute targets (e.g. AWS lambda) that initiate network connections have no built-in way of offloading that connection management in the case of long polling, websockets, http2, etc.

This means that a reactive lambda that makes an outbound network connection spends most of its execution time in an endless IO wait.

AMZN APIGW can take incoming websocket connections and translate those requests into a request/response model. This is desirable! What would be great is allowing that for outbound connections as well.

Currently the only way to do this is with an out of band proxy (typically nginx).

export class BaseStack extends cdk.Stack {
public readonly stageName?: string;
public readonly serviceName?: string;
constructor(scope: cdk.Construct, id: string, props: IBaseStack) {
const superProps = {
...(props.stageName && { stackName: `${props.stageName}-${id}` }),
...props,
};
super(scope, id, superProps);
@ranman
ranman / update_lambdas_lol.py
Last active November 18, 2019 22:40
enable python3.8 in all region
import boto3
session = boto3.Session(profile_name='default')
regions = session.get_available_regions(service_name='lambda')
for region in regions:
print(region)
aws_lambda = session.client('lambda', region_name=region)
try:
paginator = aws_lambda.get_paginator('list_functions').paginate()
for page in paginator:
for function in page['Functions']:
@ranman
ranman / ComprehendExamples.ipynb
Created May 2, 2019 22:08
Atlanta Summit Code
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Services

NEW AWS Budgets Console

NEW Neptune GA

NEW Registry of open data

NEW EKS GA

@ranman
ranman / lol.js
Created November 13, 2018 04:07
grab aws posts
var stuff = []
Array.from(document.querySelectorAll(".blog-post")).forEach(function (item) {
stuff.push({
"image": item.querySelector('.wp-post-image').src,
"url": item.querySelector('a').href,
"description": item.querySelector('p').innerText,
"title": item.querySelector('h2').innerText,
"date": item.querySelector('time').dateTime
})
})
import os
from PIL import Image, ImageFilter
import boto3
rek = boto3.client("rekognition")
def get_face_boxes(faces, source_size):
return [
(
int(f['BoundingBox']['Left'] * source_size[0]),
@ranman
ranman / lambda_function.py
Created October 22, 2018 22:33
example of translate and polly
import boto3
import random
translate = boto3.client("translate")
polly = boto3.client("polly")
def get_valid_voices_for_language(language_code="en"):
return [
voice['Id'] for voice in polly.describe_voices()['Voices']
if voice['LanguageCode'].startswith(language_code)
]