Last active
August 31, 2018 18:32
-
-
Save nimboya/69241f60b62a06709c1072203ed2c351 to your computer and use it in GitHub Desktop.
Transform Records from Kinesis using Lambda Function for JSON data
This file contains hidden or 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 math | |
| print('Loading function') | |
| def lambda_handler(event, context): | |
| output = [] | |
| for record in event['records']: | |
| payload = base64.b64decode(record['data']) | |
| entry = json.loads(payload) | |
| result = { | |
| 'date': entry['date'], | |
| 'traxid': entry['traxid'], | |
| 'discount': entry['discount'], | |
| 'amount': entry['amount'], | |
| 'currency': math.ceil(entry['currency']), | |
| } | |
| # Do custom processing on the record payload here | |
| output_record = { | |
| 'recordId': record['recordId'], | |
| 'result': 'Ok', | |
| 'data': base64.b64encode(json.dumps(result)) | |
| } | |
| output.append(output_record) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment