DEV Community

Carlos Chacin โ˜•๐Ÿ‘ฝ
Carlos Chacin โ˜•๐Ÿ‘ฝ

Posted on • Originally published at on

Java 17 + AWS Lambda


AWS recently announced Java 17 support for Lambdas, In this blog post, weโ€™ll explore how to create a Java 17 AWS Lambda Function without IDE, build tool or any dependency.

Master AWS Lambda with Java 17 in Just 2 Minutes! - YouTube

In this video, we'll show you how to set up AWS Lambda with Java 17 in just 2 minutes!Don't forget to like, comment, and subscribe for more content like this...


Fist letโ€™s create the lambda function code:

public class Function {

  public record Input(int x, int y) {}

  public record Output(long result) {}

  public Output add(Input input) {
    return new Output(input.x + input.y);

Enter fullscreen mode Exit fullscreen mode

In this example, we have an add method that takes an Input java record with 2 fields: x and y, and returns an Output java record with the sum of x and y assigned to the result field.

This is the only requirement for a AWS Lambda Function:

An instance method that takes one single parameter and returns something an object or Void.

Thatโ€™s it. Now we can proceed to compile and package our AWS Lambda Function:


$ javac

Enter fullscreen mode Exit fullscreen mode


$ zip *.class

Enter fullscreen mode Exit fullscreen mode

Next, letโ€™s navigate to the AWS Lambda Console. 2

Click on the Create function button.


Assign a lambda name and select Java 17 as the runtime.


Click on the Upload from button.


Click Upload button.


Choose the file that we generated.


Click Edit on the Code properties section.


Change the Handler to Function::add and click Save.


Go to the Test tab.


Change the JSON payload to:

  "x": 123,
  "y": 333

Enter fullscreen mode Exit fullscreen mode

Click the Test button, then expand the Details section to see the result.


Thatโ€™s it! You have successfully created and tested your Java 17 AWS Lambda function. The output should be:

  "result": 456

Enter fullscreen mode Exit fullscreen mode


This demonstrates the simplicity and power of using Java 17 with AWS Lambda. With just a few steps, you can leverage the latest Java version to build efficient and scalable serverless applications.

Feel free to explore further and unleash the full potential of Java 17 on AWS Lambda. Happy coding!

Top comments (0)