From eccaa351aa9981715b3f9d65a36375aebdc1c077 Mon Sep 17 00:00:00 2001 From: Umang-Aggarwal-07 Date: Wed, 6 Dec 2023 09:17:44 +0530 Subject: [PATCH 1/3] Add files via upload --- integration-kinesis-to-lambda/main.py | 19 ++++++++++++++++ .../snippet-data.json | 22 +++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 integration-kinesis-to-lambda/main.py diff --git a/integration-kinesis-to-lambda/main.py b/integration-kinesis-to-lambda/main.py new file mode 100644 index 0000000..e436fec --- /dev/null +++ b/integration-kinesis-to-lambda/main.py @@ -0,0 +1,19 @@ +import base64 +import json +import boto3 +def lambda_handler(event, context): + kinesis = boto3.client('kinesis') + for record in event['Records']: + try: + print(f"Processed Kinesis Event - EventID: {record['eventID']}") + record_data = get_record_data(record['kinesis']) + print(f"Record Data: {record_data}") + # TODO: Do interesting work based on the new data + except Exception as e: + print(f"An error occurred {e}") + raise e + print(f"Successfully processed {len(event['Records'])} records.") +def get_record_data(payload): + data = base64.b64decode(payload['data']).decode('utf-8') + # Placeholder for actual async work, you can use asyncio or threading for that + return data \ No newline at end of file diff --git a/integration-kinesis-to-lambda/snippet-data.json b/integration-kinesis-to-lambda/snippet-data.json index cff00d9..dcdb77f 100644 --- a/integration-kinesis-to-lambda/snippet-data.json +++ b/integration-kinesis-to-lambda/snippet-data.json @@ -3,7 +3,7 @@ "description": "Using AWS Lambda with Amazon Kinesis without Batch Item Handling.", "type": "Integration", "services": ["lambda", "kinesis"], - "languages": ["Node", "TypeScript", ".NET", "Java", "Go"], + "languages": ["Node", "TypeScript", ".NET", "Java", "Go", "Python"], "tags": [], "introBox": { "headline": "How it works", @@ -74,6 +74,17 @@ "language": "go" } ] + }, + { + "id": "Python", + "title": "Usage Example with Python:", + "description": "Consuming Kinesis event with Lambda using Python without batch item handling.", + "snippets": [ + { + "snippetPath": "main.py", + "language": "python" + } + ] } ] } @@ -101,6 +112,13 @@ "image": "https://pbs.twimg.com/profile_images/888727786797412352/DEZ1mRjs_400x400.jpg", "bio": "Solutions Architect Architect at AWS", "linkedin": "ananthanr" + }, + { + "headline": "Python Example Presented by Umang Aggarwal", + "name": "Umang Aggarwal", + "image": "https://media.licdn.com/dms/image/D5603AQGPJSLqUSGPmA/profile-displayphoto-shrink_800_800/0/1684261011000?e=1707350400&v=beta&t=YoDvcLUA8y_w5ZAq0p6wDNL5nut8PVKCUvrf6rTi43A", + "bio": "Cloud Support Engineer at AWS", + "linkedin": "umangaggarwal" } ] -} +} \ No newline at end of file From a385a2644e289089dc66b6abc7e607a32a2de45e Mon Sep 17 00:00:00 2001 From: Umang-Aggarwal-07 Date: Wed, 13 Dec 2023 13:35:01 +0530 Subject: [PATCH 2/3] Update main.py --- integration-kinesis-to-lambda/main.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/integration-kinesis-to-lambda/main.py b/integration-kinesis-to-lambda/main.py index e436fec..26cacdc 100644 --- a/integration-kinesis-to-lambda/main.py +++ b/integration-kinesis-to-lambda/main.py @@ -1,19 +1,13 @@ import base64 -import json -import boto3 def lambda_handler(event, context): - kinesis = boto3.client('kinesis') + for record in event['Records']: try: print(f"Processed Kinesis Event - EventID: {record['eventID']}") - record_data = get_record_data(record['kinesis']) + record_data = base64.b64decode(record['kinesis']['data']).decode('utf-8') print(f"Record Data: {record_data}") # TODO: Do interesting work based on the new data except Exception as e: print(f"An error occurred {e}") raise e print(f"Successfully processed {len(event['Records'])} records.") -def get_record_data(payload): - data = base64.b64decode(payload['data']).decode('utf-8') - # Placeholder for actual async work, you can use asyncio or threading for that - return data \ No newline at end of file From 00a6e6a586113ec7963a68d50cba8b09666ebfa9 Mon Sep 17 00:00:00 2001 From: David Boyne Date: Wed, 13 Dec 2023 14:11:52 +0000 Subject: [PATCH 3/3] Update integration-kinesis-to-lambda/snippet-data.json --- integration-kinesis-to-lambda/snippet-data.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-kinesis-to-lambda/snippet-data.json b/integration-kinesis-to-lambda/snippet-data.json index dcdb77f..cf24999 100644 --- a/integration-kinesis-to-lambda/snippet-data.json +++ b/integration-kinesis-to-lambda/snippet-data.json @@ -77,7 +77,7 @@ }, { "id": "Python", - "title": "Usage Example with Python:", + "title": "Usage Example with Python", "description": "Consuming Kinesis event with Lambda using Python without batch item handling.", "snippets": [ {