Skip to content

Instantly share code, notes, and snippets.

✌️
Happy coding!

Alex Casalboni alexcasalboni

✌️
Happy coding!
Block or report user

Report or block alexcasalboni

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@alexcasalboni
alexcasalboni / amazon-rekognition.md
Last active Nov 21, 2019
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 / aws-lambda-static-type-checker.md
Last active Nov 6, 2019
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 / aws-lambda-edge.md
Last active Oct 24, 2019
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 / template.yml
Created Oct 21, 2019
AWS ALB - AWS Lambda integration with CloudFormation (YAML)
View template.yml
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 / index.py
Created Oct 21, 2019
AWS ALB - AWS Lambda handler (Python)
View index.py
import json
def lambda_handler(event, context):
name = get_name(event) # extract inputs
message = get_message(name) # business logic
return build_response(message) # format output for ALB
def get_name(event):
# fetch inputs from event (could be missing)
return event['queryStringParameters'].get('name')
@alexcasalboni
alexcasalboni / index.py
Created Oct 21, 2019
AWS Lambda function (HTTP) - Both Amazon API Gateway and AWS ALB
View index.py
def handler(event, context):
input = extract_input_from_event('ALB', event)
output = my_business_logic(input)
return format_output_for('ALB', output)
def extract_input_from_event(alb_or_apigw, event):
# extract data from input event
def format_output_for(alb_or_apigw, output):
# return a json object
@alexcasalboni
alexcasalboni / response.json
Created Oct 21, 2019
AWS ALB - AWS Lambda response (JSON)
View response.json
{
"statusCode": 200,
"statusDescription": "200 OK",
"isBase64Encoded": false,
"headers": {
"Content-Type": "application/json"
},
"body": "{\"message\": \"Hello world!\"}"
}
@alexcasalboni
alexcasalboni / event.json
Created Oct 21, 2019
AWS ALB - AWS Lambda event (JSON)
View event.json
{
"requestContext": {
"elb": {
"targetGroupArn": "arn:aws:elasticloadbalancing:XXX:YYY:targetgroup/lambda-ZZZ"
}
},
"httpMethod": "GET",
"path": "/my-new-feature",
"queryStringParameters": {
"id": "123"
@alexcasalboni
alexcasalboni / aws-sam-automatic-rollback-demo.md
Last active Oct 10, 2019
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 / template.yml
Created Oct 9, 2019
Amazon Pinpoint - Custom Channel Lambda function (YAML)
View template.yml
AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
myHookFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
# ...
# all the other properties here
You can’t perform that action at this time.