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 / lex.py
Last active May 29, 2019
Amazon Lex fulfillment function - Lambda handler (Python)
View lex.py
from lex_utils import elicit_slot, delegate, close, ElicitAction, DelegateAction
from utils import validate_dialog, init_or_load_session, finalize_session, actually_book_the_hotel
def lambda_handler(event, context):
intent_name = event['currentIntent']['name']
if intent_name == 'BookHotel':
return book_hotel(event)
# elif (add more intents here)
@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 / index.py
Last active Mar 22, 2019
AWS Iot 1-Click Event - Lambda handler (Python)
View index.py
from click_handler import DailyClickHandler
def handler(event, context):
if 'deviceEvent' in event:
if 'deviceHealthMonitor' in event['deviceEvent']:
# just a health check
print("HEALTHCHECK")
print(event)
return "OK"
elif 'buttonClicked' in event['deviceEvent']:
@alexcasalboni
alexcasalboni / click_handler.py
Last active Mar 22, 2019
AWS Iot 1-Click Event - Python implementation (platform-agnostic)
View click_handler.py
import os
from datetime import date
import boto3
# read environment variables
TABLE_NAME = os.environ.get('TABLE_NAME', 'my_table_test')
region = os.environ.get('AWS_DEFAULT_REGION', 'eu-west-1')
# initialize DDB client
dynamodb = boto3.resource('dynamodb', region_name=region)
@alexcasalboni
alexcasalboni / event.json
Created Mar 7, 2019
AWS Iot 1-Click Event (JSON)
View event.json
{
"deviceEvent": {
"buttonClicked": {
"clickType": "SINGLE",
"reportedTime": "2018-05-04T23:26:33.747Z"
}
},
"deviceInfo": {
"attributes": {
"key3": "value3",
@alexcasalboni
alexcasalboni / deploy.sh
Created Mar 5, 2019
AWS Lambda for Amazon DynamoDB daily resize (deployment script)
View deploy.sh
# install AWS SAM
pip install --user aws-sam-cli
# configure your AWS credentials
aws configure
# package your raw YAML template
sam package
--template-file template.yml \
--s3-bucket YOUR_BUCKET \
@alexcasalboni
alexcasalboni / template.yml
Created Mar 5, 2019
AWS Lambda for Amazon DynamoDB daily resize (CloudFormation template)
View template.yml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Parameters:
TablePrefix:
Type: String
Resources:
TableDailyResize:
Type: AWS::Serverless::Function
Properties:
Handler: handler.daily_resize
@alexcasalboni
alexcasalboni / index.py
Created Mar 5, 2019
AWS Lambda for Amazon DynamoDB daily resize (Python handler)
View index.py
import os
from resizer import DailyResize
def daily_resize(event, context):
operation = event['Operation']
resizer = DailyResize(table_prefix=os.environ['TABLE_NAME'])
if operation == 'create_new':
resizer.create_new()
elif operation == 'resize_old':
resizer.resize_old()
@alexcasalboni
alexcasalboni / resizer.py
Last active Mar 5, 2019
AWS Lambda for Amazon DynamoDB daily resize (Python)
View resizer.py
import os
import boto3
import datetime
region = os.environ.get('AWS_DEFAULT_REGION', 'us-west-2')
dynamodb = boto3.client('dynamodb', region_name=region)
class DailyResize(object):
FIRST_DAY_RCU, FIRST_DAY_WCU = 300, 1000
@alexcasalboni
alexcasalboni / template.yml
Created Mar 3, 2019
AWS CloudFormation Macro - Transform a sub-section of the template
View template.yml
AWSTemplateFormatVersion: 2010-09-09
Resources:
MyWebsite:
Type: MyCompany::StaticWebsite
'Fn::Transform':
- Name: MyUniqueMacroName
Parameters:
# your macro parameters
You can’t perform that action at this time.