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 / index.md
Last active November 30, 2022 06:22
Bridge Function between Kinesis Streams and Step Functions

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 / handler.py
Created February 26, 2019 08:47
Amazon Kinesis Data Firehose - AWS Lambda processor
import json
from base64 import b64decode, b64encode
# some useful constants
STATUS_OK = 'Ok'
STATUS_DROPPED = 'Dropped'
STATUS_FAIL = 'ProcessingFailed'
class DroppedRecordException(Exception):
""" This exception can be raised if a record needs to be skipped/dropped """
@alexcasalboni
alexcasalboni / trigger.sql
Created June 18, 2019 09:56
Amazon Aurora MySQL - Trigger to invoke AWS Lambda
DROP TRIGGER IF EXISTS TR_contacts_on_insert;
DELIMITER ;;
CREATE TRIGGER TR_contacts_on_insert
AFTER INSERT ON Contacts
FOR EACH ROW
BEGIN
SELECT NEW.email , NEW.fullname
INTO @Email , @Fullname;
lambda_async(
'arn:aws:lambda:REGION:ACCOUNT_ID:function:SendEmailWithContact',
@alexcasalboni
alexcasalboni / index.js
Created October 9, 2019 13:11
Amazon Pinpoint - Custom Channel Lambda function (Node.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 / listPricingByRegion.js
Last active March 15, 2022 16:00
AWS Pricing API - Fetch AWS Step Functions price for all regions
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 / index.js
Last active February 22, 2022 22:45
AWS CodePilpeline - Lambda stage (Node.js)
const http = require('http');
const AWS = require('aws-sdk');
const codepipeline = new AWS.CodePipeline();
exports.handler = async (event, context) => {
// Retrieve event data
const jobData = event["CodePipeline.job"];
const jobId = jobData.id;
const url = jobData.data.actionConfiguration.configuration.UserParameters;
@alexcasalboni
alexcasalboni / aws-lambda-demo1-restful-api.py
Last active March 6, 2021 13:23
AWS Lambda Coding Session - clda.co/webinar-lambda
def lambda_handler(event, context):
name = event.get('name') or 'World'
print("Name: %s" % name)
return "Hello %s!" % name
@alexcasalboni
alexcasalboni / dyslexia.js
Created March 4, 2016 11:15
Disyxela JS
// original: http://geon.github.io/programming/2016/03/03/dsxyliea
"use strict";
$(function(){
var getTextNodesIn = function(el) {
return $(el).find(":not(iframe)").addBack().contents().filter(function() {
return this.nodeType == 3;
});
};
@alexcasalboni
alexcasalboni / 0-README.md
Last active December 11, 2020 22:41
AWS Lambda: Advanced Coding Session - clda.co/aws-lambda-webinar

AWS Lambda: Advanced Coding Session (slides)

Live demos:

  1. Amazon API Gateway Access Control
  2. Amazon Kinesis Streams processing
  3. Amazon Cognito Sync trigger
  4. AWS CloudFormation Custom Resources
@alexcasalboni
alexcasalboni / deploy.sh
Last active October 3, 2020 06:36
AWS Lambda Power Tuning - Demo Setup
# 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