diff --git a/integration-sqs-to-lambda-with-batch-item-handling/example.rb b/integration-sqs-to-lambda-with-batch-item-handling/example.rb new file mode 100644 index 0000000..e603c3d --- /dev/null +++ b/integration-sqs-to-lambda-with-batch-item-handling/example.rb @@ -0,0 +1,19 @@ +require 'json' + +def lambda_handler(event:, context:) + if event + batch_item_failures = [] + sqs_batch_response = {} + + event["Records"].each do |record| + begin + # process message + rescue StandardError => e + batch_item_failures << {"itemIdentifier" => record['messageId']} + end + end + + sqs_batch_response["batchItemFailures"] = batch_item_failures + return sqs_batch_response + end +end diff --git a/integration-sqs-to-lambda-with-batch-item-handling/snippet-data.json b/integration-sqs-to-lambda-with-batch-item-handling/snippet-data.json index b745161..12b04b7 100644 --- a/integration-sqs-to-lambda-with-batch-item-handling/snippet-data.json +++ b/integration-sqs-to-lambda-with-batch-item-handling/snippet-data.json @@ -3,7 +3,7 @@ "description": "Using an Amazon SQS trigger to invoke a Lambda function", "type": "Integration", "services": ["lambda", "sqs"], - "languages": ["Node", "TypeScript", ".NET"], + "languages": ["Node", "TypeScript", ".NET", "Ruby"], "tags": [], "introBox": { "headline": "How it works", @@ -52,6 +52,17 @@ "language": "dotnet" } ] + }, + { + "id": "Ruby", + "title": "Usage Example with Ruby:", + "description": "Consuming an SQS event with Lambda using Ruby with batch item handling.", + "snippets": [ + { + "snippetPath": "example.rb", + "language": "ruby" + } + ] } ] }