Evaluate your SIEM
Get the guideComplete visibility for DevSecOps
Reduce downtime and move from reactive to proactive monitoring.
April 15, 2025
Serverless computing is a modern cloud-based application architecture in which the application’s infrastructure and support services layer are completely abstracted from the software layer. While every application still relies on physical servers to run, serverless applications shift that responsibility to cloud service providers like Amazon Web Services (AWS).
In a truly serverless architecture paradigm, your Lambda function code runs on infrastructure hosted and managed by a third party, typically a cloud service. The provider handles everything from provisioning, scaling, load balancing, and securing the infrastructure. It also manages the AWS toolkit, operating systems, patches, serverless framework, code libraries, and all necessary support services. You only pay for the compute time your running applications use, while a serverless back end scales and load balances automatically as application load increases or decreases, making it cost-effective and scalable.
The global serverless architecture market was estimated at USD 25.3 billion in 2024 and is expected to grow at a CAGR of 14.1% from 2025 to 2030. As more developers and organizations adopt serverless computing, you need to understand how to build efficient, event-driven apps, especially with popular languages like Java.
To help you get started, let’s explore how to create a Lambda function using Java 11, connect it to Amazon DynamoDB, and gain better AWS observability with Sumo Logic’s Telemetry API integration.
AWS Lambda is a serverless, event-driven compute service that lets you run code for any type of application or backend service without provisioning or managing servers. You can trigger Lambda functions from over 200 AWS services and software-as-a-service (SaaS) applications, including Amazon CloudWatch, Amazon S3, Amazon EC2, and more.
These functions respond to events such as data flowing from an Amazon Simple Queue Service (SQS) to a Lambda function or a change in a file within Amazon S3. The event is passed into the function as the first parameter. Lambda functions are completely stateless, meaning you have no guarantee where a function will be executed or how many times it's been run on a particular instance.
AWS Lambda allows you to create a Lambda Java function, which can be uploaded and configured to execute in the AWS Cloud. Although this function can be written in various languages, we’ll focus on creating an AWS Lambda function using Java 11. We'll walk through the steps of coding, configuring, and testing your function using the AWS Console.
For this example, we’ll create a simple ZIP code validator that responds to a new address added to an Amazon DynamoDB table.
Step 0: Before you start
Make sure you have access to the AWS Management Console. Creating and deploying this example shouldn't cost anything within the AWS free tier.
Disable any triggers and delete the DynamoDB table after testing to avoid unnecessary usage.
Step 1: Create a DynamoDB table
Go to the DynamoDB console.
Create a table called US_Address_Table with a primary key of id (String type).
Enable streams with NEW_IMAGE view type.
Copy the table’s ARN for use in the next step.
Step 2: Create a role for your Lambda function
Navigate to the IAM console.
Create a new role with the AWSLambdaDynamoDBExecutionRole managed policy.
Name the role something like lambda-validator.
Step 3: Add permissions to update DynamoDB
Attach an inline policy or use the console to grant UpdateItem permissions on your DynamoDB table using the table's ARN.
Step 4: Let's code the Lambda function
Use Java 11 and the AWS SDK v2. Here's a simplified version of the Lambda function:
package com.example;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.LambdaLogger;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.*;
import com.amazonaws.services.lambda.runtime.events.DynamodbEvent;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.regex.Pattern;
public class AddressValidator implements RequestHandler<DynamodbEvent, String> {
private static final Pattern ZIP_CODE_PATTERN = Pattern.compile("^[0-9]{5}(?:-[0-9]{4})?$");
private final ObjectMapper objectMapper = new ObjectMapper();
private final DynamoDbClient dynamoDbClient = DynamoDbClient.builder().region(Region.US_WEST_2).build();
private static final String TABLE_NAME = "US_Address_Table";
public String handleRequest(DynamodbEvent event, Context context) {
LambdaLogger logger = context.getLogger();
for (DynamodbEvent.DynamodbStreamRecord record : event.getRecords()) {
if ("INSERT".equals(record.getEventName())) {
try {
String jsonAddress = record.getDynamodb().getNewImage().get("address").getS();
Address address = objectMapper.readValue(jsonAddress, Address.class);
if (!Boolean.TRUE.equals(address.getValidated())) {
address.setValidated(ZIP_CODE_PATTERN.matcher(address.getZipcode()).matches());
String updatedJson = objectMapper.writeValueAsString(address);
dynamoDbClient.updateItem(UpdateItemRequest.builder()
.tableName(TABLE_NAME)
.key(record.getDynamodb().getKeys())
.updateExpression("SET address = :a")
.expressionAttributeValues(Map.of(":a", AttributeValue.builder().s(updatedJson).build()))
.returnValues(ReturnValue.UPDATED_NEW)
.build());
}
} catch (Exception e) {
logger.log("Exception during ZIP validation: " + e.getMessage());
}
}
}
return "Validated " + event.getRecords().size() + " records.";
}
}
Step 5: Upload your Lambda function using the AWS Console
Package your Java Lambda function as a fat JAR using Maven or Gradle.
Upload it through the AWS Lambda console.
Set the runtime to Java 11 and handler to com.example.AddressValidator::handleRequest.
Assign the role you created earlier.
Step 6: Test your function synchronously within the AWS Console
Create a test event in the Lambda console.
Use this JSON format:
{
"Records": [
{
"eventID": "1",
"eventVersion": "1.0",
"dynamodb": {
"Keys": {
"id": {"S": "111-222-333"}
},
"NewImage": {
"address": {
"S": "{\"address1\":\"123 Main St\",\"city\":\"Portland\",\"state\":\"OR\",\"zipcode\":\"97229\"}"
},
"id": {"S": "111-222-333"}
},
"StreamViewType": "NEW_IMAGE",
"SequenceNumber": "111-222-333",
"SizeBytes": 26
},
"awsRegion": "us-west-2",
"eventName": "INSERT",
"eventSourceARN": "arn:aws:dynamodb:us-west-2:account-id:table/ExampleTableWithStream/stream/2023-01-01T00:00:00.000",
"eventSource": "aws:dynamodb"
}
]
}
If you get a null pointer or permissions error, check that the table’s ARN is correct and your Lambda role has the necessary permissions.
Add logger.log() statements to help debug.
Step 7: Trigger the Lambda function from DynamoDB
In the DynamoDB console, go to your table's Triggers tab and link it to your Lambda function.
Set the batch size to 1 for manual testing.
Once connected, inserting a new item into your table should trigger the Lambda and update the address object with a validated field.
With Sumo Logic’s SaaS Log Analytics Platform, you can integrate logs, platform metrics, and platform traces from AWS Lambda directly into Sumo Logic using Telemetry API. This integration enhances observability across your environment, giving you deeper visibility and easy monitoring of your Lambda function without the overhead of managing infrastructure.
Ready to take your AWS monitoring and observability to the next level? Sign up for our 30-day free trial.
Reduce downtime and move from reactive to proactive monitoring.
Build, run, and secure modern applications and cloud infrastructures.
Start free trial