SQS Large Message Handling (Deprecated)
Warning
This module is now deprecated and will be removed in version 2.
See Large Message Handling and
the migration guide
for the new module (powertools-large-messages
) documentation
The large message handling utility handles SQS messages which have had their payloads offloaded to S3 due to them being larger than the SQS maximum.
The utility automatically retrieves messages which have been offloaded to S3 using the amazon-sqs-java-extended-client-lib client library. Once the message payloads have been processed successful the utility can delete the message payloads from S3.
This utility is compatible with versions 1.1.0+ of amazon-sqs-java-extended-client-lib.
1 2 3 4 5 |
|
1 2 3 |
|
Install¶
Depending on your version of Java (either Java 1.8 or 11+), the configuration slightly changes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Lambda handler¶
The annotation @SqsLargeMessage
should be used with the handleRequest method of a class
which implements com.amazonaws.services.lambda.runtime.RequestHandler
with
com.amazonaws.services.lambda.runtime.events.SQSEvent
as the first parameter.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
@SqsLargeMessage
creates a default S3 Client AmazonS3 amazonS3 = AmazonS3ClientBuilder.defaultClient()
.
Tip
When the Lambda function is invoked with an event from SQS, each received record
in the SQSEvent is checked to see to validate if it is offloaded to S3.
If it does then getObject(bucket, key)
will be called, and the payload retrieved.
If there is an error during this process then the function will fail with a FailedProcessingLargePayloadException
exception.
1 2 |
|
To disable deletion of payloads setting the following annotation parameter:
1 2 3 4 5 6 |
|
Utility¶
If you want to avoid using annotation and have control over error that can happen during payload enrichment use SqsUtils.enrichedMessageFromS3()
.
It provides you access with a list of SQSMessage
object enriched from S3 payload.
Original SQSEvent
object is never mutated. You can also control if the S3 payload should be deleted after successful
processing.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
Overriding the default S3Client¶
If you require customisations to the default S3Client, you can create your own S3Client
and pass it to be used by utility either for
SqsLargeMessage annotation, or SqsUtils Utility API.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|