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 / 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 / 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
@alexcasalboni
alexcasalboni / index.js
Created Oct 9, 2019
Amazon Pinpoint - Custom Channel Lambda function (Node.js)
View index.js
const https = require("https");
/* FB configuration */
const FB_ACCESS_TOKEN = "EAF...DZD";
const FB_PSID = "facebookMessengerPsid";
const FB_REQUEST = {
host: "graph.facebook.com",
path: "/v2.6/me/messages?access_token=" + FB_ACCESS_TOKEN,
method: "POST",
headers: {
@alexcasalboni
alexcasalboni / template.yml
Created Oct 9, 2019
Amazon Pinpoint - Custom Segment Lambda function with centralized settings (YAML)
View template.yml
myAppSettings:
Type: AWS::Pinpoint::ApplicationSettings
Properties:
ApplicationId: !Ref myPinpointApp
CampaignHook:
LambdaFunctionName: !Ref myHookFunction
Mode: FILTER
@alexcasalboni
alexcasalboni / template.yml
Created Oct 8, 2019
Amazon Pinpoint - Custom Segment 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
@alexcasalboni
alexcasalboni / index.py
Last active Oct 8, 2019
Amazon Pinpoint - Custom Segment Lambda function (Python)
View index.py
import random
def handler(event, context):
# fetch events from input event
endpoints = event['Endpoints']
# iterate over endpoints one by one
for id, endpoint in endpoints.items():
print("Processing endpoint with id: %s" % id)
You can’t perform that action at this time.