Skip to content

Fix Golang: lambda-function-sqs-report-batch-item-failures #234

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 6 additions & 3 deletions lambda-function-sqs-report-batch-item-failures/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package main

import (
"context"
"encoding/json"
"fmt"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
Expand All @@ -14,8 +13,12 @@ func handler(ctx context.Context, sqsEvent events.SQSEvent) (map[string]interfac
batchItemFailures := []map[string]interface{}{}

for _, message := range sqsEvent.Records {

if /* Your message processing condition here */ {
if len(message.Body) > 0 {
// Your message processing condition here
fmt.Printf("Successfully processed message: %s\n", message.Body)
} else {
// Message processing failed
fmt.Printf("Failed to process message %s\n", message.MessageId)
batchItemFailures = append(batchItemFailures, map[string]interface{}{"itemIdentifier": message.MessageId})
}
}
Expand Down
2 changes: 1 addition & 1 deletion lambda-function-sqs-report-batch-item-failures/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def lambda_handler(event, context):

for record in event["Records"]:
try:
# process message
print(f"Processed message: {record['body']}")
except Exception as e:
batch_item_failures.append({"itemIdentifier": record['messageId']})

Expand Down