Skip to content

Instantly share code, notes, and snippets.

@alexcasalboni
Last active October 8, 2019 14:21
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 alexcasalboni/46fe3f99ccdf3cea93aad1957b3292a5 to your computer and use it in GitHub Desktop.
Save alexcasalboni/46fe3f99ccdf3cea93aad1957b3292a5 to your computer and use it in GitHub Desktop.
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