Skip to content

Instantly share code, notes, and snippets.

@sjparkinson
Last active April 17, 2016 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjparkinson/f846502460071c4af703 to your computer and use it in GitHub Desktop.
Save sjparkinson/f846502460071c4af703 to your computer and use it in GitHub Desktop.
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