From 55b3222513eb8a98c43cbf3015f8121e7bd0c400 Mon Sep 17 00:00:00 2001 From: ssnskar Date: Thu, 11 Jan 2024 14:57:50 +0530 Subject: [PATCH 1/4] Update snippet-data.json --- .../snippet-data.json | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/integration-kinesis-to-lambda/snippet-data.json b/integration-kinesis-to-lambda/snippet-data.json index ee904c2..e8a8e6a 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", "Python"], + "languages": ["Node", "TypeScript", ".NET", "Java", "Go", "Python","Ruby"], "tags": [], "introBox": { "headline": "How it works", @@ -96,6 +96,17 @@ "language": "python" } ] + }, + { + "id": "Ruby", + "title": "Usage Example with Ruby:", + "description": "Consuming Kinesis event with Lambda using Ruby without batch item handling.", + "snippets": [ + { + "snippetPath": "example.rb", + "language": "rb" + } + ] } ] } @@ -130,6 +141,12 @@ "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" + }, + { + "headline": "Ruby Example Presented by Sanskar", + "name": "Sanskar", + "bio": "Cloud Support Engineer at AWS", + "linkedin": "Sanskar05" } ] -} \ No newline at end of file +} From 5265086ed3f4539ed4ea95946b401505df654b5f Mon Sep 17 00:00:00 2001 From: ssnskar Date: Thu, 11 Jan 2024 14:58:26 +0530 Subject: [PATCH 2/4] Add files via upload --- integration-kinesis-to-lambda/example.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 integration-kinesis-to-lambda/example.rb diff --git a/integration-kinesis-to-lambda/example.rb b/integration-kinesis-to-lambda/example.rb new file mode 100644 index 0000000..9899490 --- /dev/null +++ b/integration-kinesis-to-lambda/example.rb @@ -0,0 +1,23 @@ +require 'aws-sdk' + +def lambda_handler(event:, context:) + event['Records'].each do |record| + begin + puts "Processed Kinesis Event - EventID: #{record['eventID']}" + record_data = get_record_data_async(record['kinesis']) + puts "Record Data: #{record_data}" + # TODO: Do interesting work based on the new data + rescue => err + $stderr.puts "An error occurred #{err}" + raise err + end + end + puts "Successfully processed #{event['Records'].length} records." +end + +def get_record_data_async(payload) + data = Base64.decode64(payload['data']).force_encoding('UTF-8') + # Placeholder for actual async work + # You can use Ruby's asynchronous programming tools like async/await or fibers here. + return data +end \ No newline at end of file From bcc69c918282296bddb3e2868a259a227f7d6872 Mon Sep 17 00:00:00 2001 From: ssnskar Date: Thu, 11 Jan 2024 15:00:24 +0530 Subject: [PATCH 3/4] Update snippet-data.json --- .../snippet-data.json | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/integration-kinesis-to-lambda-with-batch-item-handling/snippet-data.json b/integration-kinesis-to-lambda-with-batch-item-handling/snippet-data.json index 1e68eac..f6ce74b 100644 --- a/integration-kinesis-to-lambda-with-batch-item-handling/snippet-data.json +++ b/integration-kinesis-to-lambda-with-batch-item-handling/snippet-data.json @@ -3,7 +3,7 @@ "description": "Using AWS Lambda with Amazon Kinesis with Batch Item Handling.", "type": "Integration", "services": ["lambda", "kinesis"], - "languages": ["Node", "TypeScript", ".NET"], + "languages": ["Node", "TypeScript", ".NET","Ruby"], "tags": [], "introBox": { "headline": "How it works", @@ -75,6 +75,17 @@ } ] }, + { + "id": "Ruby", + "title": "Usage Example with Ruby:", + "description": "Consuming Kinesis event with Lambda using Ruby with batch item handling.", + "snippets": [ + { + "snippetPath": "example.rb", + "language": "rb" + } + ] + }, { "id": "Rust", "title": "Usage Example with Rust:", @@ -105,6 +116,13 @@ "bio": "Cloud Application Architect at AWS", "linkedin": "mtomeh", "twitter": "mtomeh84" + }, + { + "headline": "Ruby Example Presented by Sanskar", + "name": "Sanskar", + "bio": "Cloud Support Engineer at AWS", + "linkedin": "Sanskar05" + } ] } From c64be4d817880555f0d0511680802b7f0364aacc Mon Sep 17 00:00:00 2001 From: ssnskar Date: Thu, 11 Jan 2024 15:01:15 +0530 Subject: [PATCH 4/4] Add files via upload --- example.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 example.rb diff --git a/example.rb b/example.rb new file mode 100644 index 0000000..019ad3a --- /dev/null +++ b/example.rb @@ -0,0 +1,29 @@ +require 'aws-sdk' + +def lambda_handler(event:, context:) + batch_item_failures = [] + + event['Records'].each do |record| + begin + puts "Processed Kinesis Event - EventID: #{record['eventID']}" + record_data = get_record_data_async(record['kinesis']) + puts "Record Data: #{record_data}" + # TODO: Do interesting work based on the new data + rescue StandardError => err + puts "An error occurred #{err}" + # Since we are working with streams, we can return the failed item immediately. + # Lambda will immediately begin to retry processing from this failed item onwards. + return { batchItemFailures: [{ itemIdentifier: record['kinesis']['sequenceNumber'] }] } + end + end + + puts "Successfully processed #{event['Records'].length} records." + { batchItemFailures: batch_item_failures } +end + +def get_record_data_async(payload) + data = Base64.decode64(payload['data']).force_encoding('utf-8') + # Placeholder for actual async work + sleep(1) + data +end \ No newline at end of file