Last active
February 11, 2020 08:44
-
-
Save qi-qi/8ad668a18526fdb30e5d9d3d5ed9d45f to your computer and use it in GitHub Desktop.
sample code to put record to kinesis firehose
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
# Message in payload should be single-line minimized json + newline '\n' append at the end of each line: | |
# eg: | |
# {"id": 111, "name": "QiQi", "email": "[email protected]"} | |
# {"id": 222, "name": "Hello", "email": "[email protected]"} | |
# {"id": 333, "name": "tv", "email": "[email protected]"} | |
import boto3 | |
import json | |
client = boto3.client('firehose', aws_access_key_id='aaa', aws_secret_access_key='bbb', region_name='eu-west-1') | |
payload1 = json.dumps({ | |
'id': 111, | |
'name': 'QiQi', | |
'email': '[email protected]' | |
}) | |
response1 = client.put_record( | |
DeliveryStreamName='tv-stream-test', | |
Record={'Data': payload1 + '\n'} | |
) | |
print(response1) | |
###### Put Records in Batch ###### | |
payload2 = json.dumps({ | |
'id': 222, | |
'name': 'Hello', | |
'email': '[email protected]' | |
}) | |
payload3 = json.dumps({ | |
'id': 333, | |
'name': 'tv', | |
'email': '[email protected]' | |
}) | |
response2 = client.put_record_batch( | |
DeliveryStreamName='tv-stream-test', | |
Records=[{'Data': payload2 + '\n'}, {'Data': payload3 + '\n'}] | |
) | |
print(response2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment