Last active
April 17, 2016 22:11
-
-
Save sjparkinson/f846502460071c4af703 to your computer and use it in GitHub Desktop.
This file contains 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 boto3 | |
import json | |
import logging | |
import requests | |
from datetime import datetime | |
logger = logging.getLogger() | |
logger.setLevel(logging.INFO) | |
def handler(event, context): | |
logger.info("Received event: {}".format(json.dumps(event))) | |
# Assert required keys exist. | |
for key in ['name', 'value', 'source']: | |
if key not in event: | |
logger.error('The `{}` key was missing from the event.'.format(key)) | |
raise KeyError(key) | |
# Handle GCM notification for handset-activated events. | |
if 'name' in event and event['name'] == 'gatekeeper/handset-activated': | |
# Publish to SNS | |
client = boto3.client('sns') | |
client.publish( | |
TopicArn = 'arn:aws:sns:eu-west-1:<arn-number>:HandsetActivations', | |
Message = json.dumps({ | |
'default': 'Handset activated!', | |
'GCM': '{"data": {"event": "handset-activated"}, "priority": "high", "time_to_live": 120, "collapse_key": "handset-activated" }' | |
}), | |
MessageStructure = 'json' | |
) | |
return "Thanks!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment