Skip to content

Instantly share code, notes, and snippets.

View alexcasalboni's full-sized avatar
✌️
Happy coding!

Alex Casalboni alexcasalboni

✌️
Happy coding!
View GitHub Profile
@alexcasalboni
alexcasalboni / README.md
Last active April 5, 2024 10:49
Google Vision API Examples - FACE DETECTION
@alexcasalboni
alexcasalboni / deploy.sh
Last active January 29, 2024 12:22
Simple AWS Lambda deployment script - Zip & upload Deployment Package with initial dependencies to S3
#!/bin/bash
BUCKET="YOUR_BUCKET_NAME" # bucket name
FILENAME="deployment-package.zip" # upload key
TMP_FOLDER="/tmp/lambda-env-tmp/" # will be cleaned
OUTPUT_FOLDER="/tmp/lambda-env/" # will be cleaned
HERE=${BASH_SOURCE%/*} # relative path to this file's folder
LAMBDA_FOLDER="$HERE/lambda/" # relative path
@alexcasalboni
alexcasalboni / template.yml
Created October 21, 2019 13:56
AWS ALB - AWS Lambda integration with CloudFormation (YAML)
AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Parameters:
Subnets:
Type: List<AWS::EC2::Subnet::Id>
VpcId:
Type: AWS::EC2::VPC::Id
Resources:
@alexcasalboni
alexcasalboni / aws-lambda-edge.md
Last active September 8, 2023 08:44
Serve dynamically generated, minimized and compressed HTML pages with AWS Lambda@Edge.

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 / amazon-rekognition.md
Last active September 6, 2023 15:20
Amazon Rekognition - Python Code Samples

Amazon Rekognition - Python Code Samples

  1. Labels Detection
  2. Faces Detection
  3. Faces Comparison
  4. Faces Indexing
  5. Faces Search
@alexcasalboni
alexcasalboni / lex.py
Created May 29, 2019 17:49
Amazon Lex fulfillment function - Lambda handler (Python) + utilities
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 / aws-lambda-static-type-checker.md
Last active May 22, 2023 07:31
AWS Lambda Static Type Checker Example (Python3)

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 / decode.js
Created June 17, 2019 16:34
How to decode CloudWatch Logs events
const zlib = require('zlib');
exports.decode = async (data) => {
const compressedPayload = Buffer.from(data, 'base64');
const jsonPayload = zlib.gunzipSync(compressedPayload).toString('utf8');
return JSON.parse(jsonPayload);
}
@alexcasalboni
alexcasalboni / aws-sam-automatic-rollback-demo.md
Last active March 22, 2023 05:27
AWS SAM Demo - Automatic Rollback for AWS Lambda with AWS CodeDeploy

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)