Skip to content

Added Ruby example in Lambda-SQS with Batch failures #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions integration-sqs-to-lambda-with-batch-item-handling/example.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
]
}
]
}
Expand Down