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 Jul 19, 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 / 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 / template.yml
Last active Jul 1, 2019
AWS Iot 1-Click Event - CloudFormation template (YAML)
View template.yml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
MyClickFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: python2.7
# ...
# all the other properties here
@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
@alexcasalboni
alexcasalboni / template.yml
Created Jun 17, 2019
CloudWatch Logs - serverless app for logs processing
View template.yml
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Resources:
MyProcessingFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: python3.7
Policies:
- AWSLambdaExecute # Managed Policy
@alexcasalboni
alexcasalboni / handler.py
Last active Jun 17, 2019
AWS CloudWatch Logs - Lambda handler
View handler.py
import time
import boto3
from decode import decode # see decode.py
cloudwatch_logs = boto3.client('logs')
def handler(event, context):
obj = decode(event['awslogs']['data'])
# wait for other logs to be collected in the stream
View payload.json
{
"messageType": "DATA_MESSAGE",
"owner": "123456789123",
"logGroup": "myLogGroup",
"logStream": "myLogStream",
"subscriptionFilters": [
"mySubscriptionFilter"
],
"logEvents": [
{
@alexcasalboni
alexcasalboni / decode.js
Created Jun 17, 2019
How to decode CloudWatch Logs events
View decode.js
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);
}
You can’t perform that action at this time.