// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.// SPDX-License-Identifier: Apache-2.0using Amazon.Lambda.Core;
using Amazon.Lambda.SQSEvents;
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
namespacesqsSample;
publicclassFunction{publicasync Task<SQSBatchResponse> FunctionHandler(SQSEvent evnt, ILambdaContext context){
List<SQSBatchResponse.BatchItemFailure> batchItemFailures = new List<SQSBatchResponse.BatchItemFailure>();
foreach(var message in evnt.Records)
{try{//process your messageawait ProcessMessageAsync(message, context);
}
catch (System.Exception)
{//Add failed message identifier to the batchItemFailures list
batchItemFailures.Add(new SQSBatchResponse.BatchItemFailure{ItemIdentifier=message.MessageId});
}
}
returnnew SQSBatchResponse(batchItemFailures);
}
privateasync Task ProcessMessageAsync(SQSEvent.SQSMessage message, ILambdaContext context){if (String.IsNullOrEmpty(message.Body))
{thrownew Exception("No Body in SQS Message.");
}
context.Logger.LogInformation($"Processed message {message.Body}");
// TODO: Do interesting work based on the new messageawait Task.CompletedTask;
}
}
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.# SPDX-License-Identifier: Apache-2.0deflambda_handler(event, context):if event:
batch_item_failures = []
sqs_batch_response = {}
for record in event["Records"]:
try:
# process messageexcept Exception as e:
batch_item_failures.append({"itemIdentifier": record['messageId']})
sqs_batch_response["batchItemFailures"] = batch_item_failures
return sqs_batch_response
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.// SPDX-License-Identifier: Apache-2.0using Amazon.Lambda.Core;
using Amazon.Lambda.SQSEvents;
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
namespacesqsSample;
publicclassFunction{publicasync Task<SQSBatchResponse> FunctionHandler(SQSEvent evnt, ILambdaContext context){
List<SQSBatchResponse.BatchItemFailure> batchItemFailures = new List<SQSBatchResponse.BatchItemFailure>();
foreach(var message in evnt.Records)
{try{//process your messageawait ProcessMessageAsync(message, context);
}
catch (System.Exception)
{//Add failed message identifier to the batchItemFailures list
batchItemFailures.Add(new SQSBatchResponse.BatchItemFailure{ItemIdentifier=message.MessageId});
}
}
returnnew SQSBatchResponse(batchItemFailures);
}
privateasync Task ProcessMessageAsync(SQSEvent.SQSMessage message, ILambdaContext context){if (String.IsNullOrEmpty(message.Body))
{thrownew Exception("No Body in SQS Message.");
}
context.Logger.LogInformation($"Processed message {message.Body}");
// TODO: Do interesting work based on the new messageawait Task.CompletedTask;
}
}