in lambdas/stream_station_status_to_s3/index.py [0:0]
def lambda_handler(event, context):
record_count = 0
for record in event['Records']:
# Get the primary key of the station
station_id = record['dynamodb']['Keys']['station_id']['N']
if record['eventName'] != 'REMOVE':
new_image = record['dynamodb']['NewImage']
deserializer = TypeDeserializer()
payload = json.dumps({k: deserializer.deserialize(v) for k, v in new_image.items()}, cls=DecimalEncoder)
response = client.put_record(
DeliveryStreamName = FIREHOSE_STREAM_NAME,
Record = { 'Data': payload + '\r\n' }
)
print('[DEBUG] Processed station_id: {}. Request response: {}'.format(station_id, payload))
record_count += 1
print("[INFO] Processed {} records.".format(str(record_count)))