You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Powertools for AWS Lambda (Java) - Kafka Example
1
+
# Powertools for AWS Lambda (Java) - Large Messages Example
2
2
3
-
This project demonstrates how to use Powertools for AWS Lambda (Java) to deserialize Kafka Lambda events directly into strongly typed Kafka ConsumerRecords<K, V> using different serialization formats.
3
+
This project contains an example of a Lambda function using the **Large Messages** module of Powertools for AWS Lambda (Java). For more information on this module, please refer to the [documentation](https://docs.powertools.aws.dev/lambda-java/utilities/large_messages/).
4
4
5
-
## Overview
5
+
The example demonstrates an SQS listener that processes messages using the `LargeMessages` functional utility. It handles the retrieval of large payloads offloaded to S3 automatically.
6
6
7
-
The example showcases automatic deserialization of Kafka Lambda events into ConsumerRecords using three formats:
8
-
- JSON - Using standard JSON serialization
9
-
- Avro - Using Apache Avro schema-based serialization
10
-
- Protobuf - Using Google Protocol Buffers serialization
7
+
## Deploy the sample application
11
8
12
-
Each format has its own Lambda function handler that demonstrates how to use the `@Deserialization` annotation with the appropriate `DeserializationType`, eliminating the need to handle complex deserialization logic manually.
9
+
This sample is based on Serverless Application Model (SAM). To deploy it, check out the instructions for getting
10
+
started with SAM in [the examples directory](../README.md).
13
11
14
-
## Build and Deploy
12
+
## Test the application
15
13
16
-
### Prerequisites
17
-
-[AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)
18
-
- Java 11+
19
-
- Maven
14
+
Since this function is triggered by an SQS Queue, you can test it by sending a message to the queue created by the SAM template.
20
15
21
-
### Build
16
+
1.**Find your Queue URL:**
17
+
Run the following command (replacing `LargeMessageExample` with the name of your deployed stack):
18
+
```bash
19
+
aws cloudformation describe-stacks --stack-name LargeMessageExample --query "Stacks[0].Outputs[?OutputKey=='QueueURL'].OutputValue" --output text
22
20
23
-
```bash
24
-
# Build the application
25
-
sam build
26
-
```
21
+
2. **Send a Test Message:**
22
+
Note: To testthe actual "Large Message" functionality (payload offloading), you would typically use the SQS Extended Client in a producer application. However, you can verify the Lambda trigger with a standard message:
23
+
```bash
24
+
aws sqs send-message --queue-url [YOUR_QUEUE_URL] --message-body '{"message": "Hello from CLI"}'
27
25
28
-
### Deploy
29
-
30
-
```bash
31
-
# Deploy the application to AWS
32
-
sam deploy --guided
33
-
```
34
-
35
-
During the guided deployment, you'll be prompted to provide values for required parameters. After deployment, SAM will output the ARNs of the deployed Lambda functions.
36
-
37
-
### Build with Different Serialization Formats
38
-
39
-
The project includes Maven profiles to build with different serialization formats:
40
-
41
-
```bash
42
-
# Build with JSON only (no Avro or Protobuf)
43
-
mvn clean package -P base
44
-
45
-
# Build with Avro only
46
-
mvn clean package -P avro-only
47
-
48
-
# Build with Protobuf only
49
-
mvn clean package -P protobuf-only
50
-
51
-
# Build with all formats (default)
52
-
mvn clean package -P full
53
-
```
54
-
55
-
## Testing
56
-
57
-
The `events` directory contains sample events for each serialization format:
58
-
-`kafka-json-event.json` - Sample event with JSON-serialized products
59
-
-`kafka-avro-event.json` - Sample event with Avro-serialized products
60
-
-`kafka-protobuf-event.json` - Sample event with Protobuf-serialized products
61
-
62
-
You can use these events to test the Lambda functions:
63
-
64
-
```bash
65
-
# Test the JSON deserialization function
66
-
sam local invoke JsonDeserializationFunction --event events/kafka-json-event.json
67
-
68
-
# Test the Avro deserialization function
69
-
sam local invoke AvroDeserializationFunction --event events/kafka-avro-event.json
70
-
71
-
# Test the Protobuf deserialization function
72
-
sam local invoke ProtobufDeserializationFunction --event events/kafka-protobuf-event.json
73
-
```
74
-
75
-
## Sample Generator Tool
76
-
77
-
The project includes a tool to generate sample JSON, Avro, and Protobuf serialized data. See the [tools/README.md](tools/README.md) for more information.
26
+
3. **Verify Logs:**
27
+
Go to AWS CloudWatch Logs and check the Log Group for your function. You should see the processed message logged by the application.
0 commit comments