Last active
October 8, 2019 14:21
-
-
Save alexcasalboni/46fe3f99ccdf3cea93aad1957b3292a5 to your computer and use it in GitHub Desktop.
Amazon Pinpoint - Custom Segment Lambda function (Python)
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 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