Skip to content

Instantly share code, notes, and snippets.

Avatar
✌️
Happy coding!

Alex Casalboni alexcasalboni

✌️
Happy coding!
View GitHub Profile
@alexcasalboni
alexcasalboni / aws-lambda-static-type-checker.md
Last active Oct 14, 2020
AWS Lambda Static Type Checker Example (Python3)
View aws-lambda-static-type-checker.md

How to use Python3 Type Hints in AWS Lambda

TL;DR

Static Type Checkers help you find simple (but subtle) bugs in your Python code. Check out lambda_types.py and incrementally improve your code base and development/debugging experience with type hints.

Your Lambda Function code will go from this:

@alexcasalboni
alexcasalboni / deploy.sh
Last active Oct 3, 2020
AWS Lambda Power Tuning - Demo Setup
View deploy.sh
# config
BUCKET_NAME=your-bucket-name
STACK_NAME=lambda-power-tuning-demo
# package
sam package --s3-bucket $BUCKET_NAME --template-file template.yml --output-template-file packaged.yml
# deploy
sam deploy --template-file packaged.yml --stack-name $STACK_NAME --capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_IAM
@alexcasalboni
alexcasalboni / amazon-rekognition.md
Last active Oct 1, 2020
Amazon Rekognition - Python Code Samples
View amazon-rekognition.md

Amazon Rekognition - Python Code Samples

  1. Labels Detection
  2. Faces Detection
  3. Faces Comparison
  4. Faces Indexing
  5. Faces Search
@alexcasalboni
alexcasalboni / index.md
Last active Sep 15, 2020
Bridge Function between Kinesis Streams and Step Functions
View index.md

Bridge Function between Kinesis Streams and Step Functions

For each record read from the Kinesis Stream, a StepFunction state machine will be executed asynchronously.

Required Environment Variables

  • region: the AWS region where your StepFunction state machine is defined.
  • stateMachineArn: the ARN of the StepFunction state machine you want to execute.

Notes

@alexcasalboni
alexcasalboni / lex.py
Created May 29, 2019
Amazon Lex fulfillment function - Lambda handler (Python) + utilities
View lex.py
import logging
from lex_utils import elicit_slot, delegate, close, ElicitAction, DelegateAction
from utils import validate_dialog, init_or_load_session, finalize_session, actually_book_the_hotel
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
def lambda_handler(event, context):
logger.debug('event.bot.name=%s', event['bot']['name'])
logger.debug('userId=%s, intentName=%s', event['userId'], event['currentIntent']['name'])
@alexcasalboni
alexcasalboni / listPricingByRegion.js
Last active May 5, 2020
AWS Pricing API - Fetch AWS Step Functions price for all regions
View listPricingByRegion.js
const AWS = require('aws-sdk');
const pricing = new AWS.Pricing({region: 'us-east-1'});
const main = async () => {
const output = {};
const prices = await pricing.getProducts({
ServiceCode: "AmazonStates",
@alexcasalboni
alexcasalboni / aws-lambda-edge.md
Last active Mar 18, 2020
Serve dynamically generated, minimized and compressed HTML pages with AWS Lambda@Edge.
View aws-lambda-edge.md

AWS Lambda@Edge Experiment

Requirements

  • AWS Lambda@Edge (enabled Preview)
  • One Amazon CloudFront Distribution (origin doesn't matter)
  • IAM role (basic execution is enough)
  • npm to install Node.js dependencies
@alexcasalboni
alexcasalboni / aws-sam-automatic-rollback-demo.md
Last active Mar 8, 2020
AWS SAM Demo - Automatic Rollback for AWS Lambda with AWS CodeDeploy
View aws-sam-automatic-rollback-demo.md

How to Build and Deploy Serverless Apps [AWS Summit]

This demo was presented at the AWS Summit @ Cape Town on Jul 12th.

You can find the slides here.

What's included in this Gist?

  • index.js: The node.js code used for AWS Lambda
  • sam_template.yaml: The AWS SAM template in YAML format (i.e. CloudFormation)
@alexcasalboni
alexcasalboni / google.py
Last active Jan 21, 2020
Google Prediction API - Train a classification model and generate a new Prediction
View google.py
import httplib2, argparse, os, sys, json
from oauth2client import tools, file, client
from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient import discovery
from googleapiclient.errors import HttpError
#Project and model configuration
project_id = '132567073760'
model_id = 'HAR-model'
You can’t perform that action at this time.