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 / event.json
Last active Oct 8, 2019
Amazon Pinpoint - AWS Lambda event (JSON)
View event.json
{
"MessageConfiguration": {...},
"ApplicationId": "ABC",
"CampaignId": "XYZ",
"TreatmentId": "XYZ2",
"ActivityId": "123",
"ScheduledTime": "2019-10-08T15:00:00.000Z",
"Endpoints": {...}
}
@alexcasalboni
alexcasalboni / template.yml
Last active Oct 8, 2019
AWS CodePilpeline - Lambda stage (YAML)
View template.yml
AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
myPipelineFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Policies:
- AWSLambdaExecute # Managed Policy
@alexcasalboni
alexcasalboni / index.js
Last active Oct 8, 2019
AWS CodePilpeline - Lambda stage (Node.js)
View index.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 / template.yml
Last active Oct 2, 2019
AWS CodeDeploy - Lambda pre-traffic hook (YAML)
View template.yml
AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
myFunctionToBeDeployed:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
AutoPublishAlias: live
DeploymentPreference:
Type: Linear10PercentEvery1Minute
@alexcasalboni
alexcasalboni / index.js
Last active Oct 2, 2019
AWS CodeDeploy - Lambda hook (Node.js)
View index.js
const AWS = require('aws-sdk');
const codedeploy = new AWS.CodeDeploy();
exports.handler = async (event, context) => {
const {DeploymentId, LifecycleEventHookExecutionId} = event;
const functionToTest = process.env.NewVersion; // to be defined in CFN
/* Enter validation tests here */
const status = 'Succeeded'; // 'Succeeded' or 'Failed'
@alexcasalboni
alexcasalboni / primes.py
Created Sep 30, 2019
Primes Test with AWS Lambda
View primes.py
import json
import numpy as np
def compute_primes_up_to(n):
# https://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188
""" Input n>=6, Returns a array of primes, 2 <= p < n """
sieve = np.ones(int(n/3) + (n%6==2), dtype=np.bool)
sieve[0] = False
for i in range(int(int(n**0.5)/3+1)):
if sieve[i]:
@alexcasalboni
alexcasalboni / recording.py
Created Jul 5, 2019
Console Recorder for AWS - Bug
View recording.py
# pip install boto3
import boto3
lambda_client = boto3.client('lambda', region_name='us-west-2')
response = lambda_client.list_functions()
iam_client = boto3.client('iam', region_name='us-west-2')
@alexcasalboni
alexcasalboni / query.sql
Created Jun 18, 2019
Amazon Aurora MySQL - Invoking Lambda functions synchronously
View query.sql
SELECT *
FROM weather_mapping
WHERE
weather = lambda_sync (
'arn:aws:lambda:REGION:ACCOUNT_ID:function:FetchWeather',
'{ "location" : "London" }'
)
@alexcasalboni
alexcasalboni / trigger.sql
Created Jun 18, 2019
Amazon Aurora MySQL - Trigger to invoke AWS Lambda
View trigger.sql
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 / grant.sql
Created Jun 18, 2019
Amazon Aurora MySQL - Grant permissions to invoke AWS Lambda
View grant.sql
GRANT INVOKE LAMBDA ON *.* TO user@domain-or-ip-address
You can’t perform that action at this time.