This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"deviceEvent": { | |
"buttonClicked": { | |
"clickType": "SINGLE", | |
"reportedTime": "2018-05-04T23:26:33.747Z" | |
} | |
}, | |
"deviceInfo": { | |
"attributes": { | |
"key3": "value3", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: 2010-09-09 | |
Resources: | |
MyWebsite: | |
Type: MyCompany::StaticWebsite | |
'Fn::Transform': | |
- Name: MyUniqueMacroName | |
Parameters: | |
# your macro parameters |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: 2010-09-09 | |
Transform: MyUniqueMacroName | |
Resources: | |
MyWebsite: | |
Type: MyCompany::StaticWebsite |