@Retention(value=RUNTIME)
@Target(value=METHOD)
public @interface LargeMessage
Use this annotation to handle large messages (> 256 KB) from SQS or SNS. When large messages are sent to an SQS Queue or SNS Topic, they are offloaded to S3 and only a reference is passed in the message/record.
@LargeMessage automatically retrieves and deletes messages
which have been offloaded to S3 using the amazon-sqs-java-extended-client-lib or amazon-sns-java-extended-client-lib
client libraries.
This version of the @LargeMessage is compatible with version
1.1.0+ of amazon-sqs-java-extended-client-lib / amazon-sns-java-extended-client-lib.
Put this annotation on a method where the first parameter is either a SQSEvent.SQSMessage or SNSEvent.SNSRecord.
SQS:
@LargeMessage
private void processRawMessage(SQSMessage sqsMessage, Context context) {
// sqsMessage.getBody() will contain the content of the S3 Object
}
SNS:
@LargeMessage
private void processMessage(SNSRecord snsRecord) {
// snsRecord.getSNS().getMessage() will contain the content of the S3 Object
}
To disable the deletion of S3 objects, you can configure the deleteS3Object option to false (default is true):
@LargeMessage(deleteS3Object = false)
Note 1: Retrieving payloads and deleting objects from S3 will increase the duration of the Lambda function.
Note 2: Make sure to configure your function with enough memory to be able to retrieve S3 objects.
| Modifier and Type | Optional Element and Description |
|---|---|
boolean |
deleteS3Object
Specify if S3 objects must be deleted after being processed (default = true)
Alternatively you might consider using S3 lifecycle policies to remove the payloads automatically after a period of time.
|
Copyright © 2025. All rights reserved.