Skip to content

Instantly share code, notes, and snippets.

@alexcasalboni alexcasalboni/index.py
Last active Oct 8, 2019

Embed
What would you like to do?
Amazon Pinpoint - Custom Segment Lambda function (Python)
import random
def handler(event, context):
# fetch events from input event
endpoints = event['Endpoints']
# iterate over endpoints one by one
for id, endpoint in endpoints.items():
print("Processing endpoint with id: %s" % id)
# don't include enpoints if not APNS
if endpoint['ChannelType'] != 'APNS':
endpoints.pop(id)
continue
# generate new CreditScore if missing, only for active endpoints
if endpoint['EndpointStatus'] == 'ACTIVE':
# add 'Attributes' if missing
endpoint['Attributes'] = endpoint.get('Attributes', {})
# add new random CreditScore -> [0, 100]
endpoint['Attributes']['CreditScore'] = random.randint(0,101)
print("New endpoints: %s" % endpoints)
return endpoints
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.