Last active
July 5, 2022 17:04
-
-
Save kevinjnguyen/2b2177b993ccf631082ce0c0da40a2a5 to your computer and use it in GitHub Desktop.
Read Segment Header API Key
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 boto3 | |
import json | |
def lambda_handler(event, context): | |
... | |
str_event = json.dumps(event) | |
partition_key = event['userId'] | |
stream_name = 'Segment' | |
try: | |
client = boto3.client('kinesis') | |
client.put_record( | |
StreamName=stream_name, | |
Data=str.encode(str_event), | |
PartitionKey=partition_key, | |
) | |
# Return 202 to indicate that the event is received but not processed | |
response = { | |
'statusCode': '202', | |
'headers': { | |
'Content-Type': 'application/json', | |
} | |
} | |
except ProvisionedThroughputExceededException as e: | |
response = { | |
'statusCode': '429', | |
'headers': { | |
'Content-Type': 'application/json', | |
} | |
} | |
except Exception as e: | |
print('Exception occurred: {}'.format(e)) | |
response = { | |
'statusCode': '500', | |
'headers': { | |
'Content-Type': 'application/json', | |
} | |
} | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment