Skip to content

Instantly share code, notes, and snippets.

@nimboya
Last active August 31, 2018 18:32
Show Gist options
  • Select an option

  • Save nimboya/69241f60b62a06709c1072203ed2c351 to your computer and use it in GitHub Desktop.

Select an option

Save nimboya/69241f60b62a06709c1072203ed2c351 to your computer and use it in GitHub Desktop.
Transform Records from Kinesis using Lambda Function for JSON data
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