Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.