News

AWS Lambda Functions Opened Up to Java

Amazon's Jeff Barr said "you will soon be able to write your Lambda functions in Java!" when he announced the event-driven cloud compute service had been moved from preview into production a couple months ago.

Yesterday he announced that "soon" is "now."

"Today we are making Lambda even more useful by giving you the ability to write your Lambda functions in Java," said Barr, evangelist for Amazon Web Services Inc. (AWS), in a blog post. "We have had many requests for this and the team is thrilled to be able to respond."

Previously, functions for use in Lambda -- launched last November as a preview -- were written in Node.js, the JavaScript framework tailored for back-end, server-side work.

Lambda functions provide event-driven capabilities, making them a good fit for -- among other things -- mobile back-end systems and supporting infrastructure for Web or Internet of Things (IoT) applications. "After you create your Lambda function it is always ready to run as soon as it is triggered, similar to a formula in a spreadsheet," the Lambda page of the AWS site says. "Each function includes your code as well as some associated configuration information, including the function name and resource requirements."

The Lambda code can be associated with different AWS resources, such as storage, database, data processing stream or SNS notifications, to respond to different events, such as an image upload to a storage (S3) instance, an incoming Amazon Kinesis stream message or an update to an Amazon DynamoDB table.

Authoring a Lambda Function
[Click on image for larger view.] Authoring a Lambda Function (source: AWS)

"AWS Lambda typically runs your code within milliseconds of an event," AWS said. "The service automatically manages the compute capacity for you and spins up the necessary infrastructure, deploys your code and runs it for each event. Each event is processed individually so thousands of functions can run in parallel and performance remains consistently high regardless of the frequency of events."

Developers can use Java 8, introduced last year, and any of the usual Java libraries, along with the AWS SDK for Java. AWS provides two libraries for Lambda, aws-lambda-java-core for function handlers and a context object, and aws-lambda-java-events for event source type definitions. The AWS Toolkit for Eclipse can be used to generate ZIP files of compiled code and any needed JAR files. AWS has provided guidance on using the Java deployment tools Maven and Gradle.

"Your build process should mimic the same build process you would use to compile any Java code that depends on the AWS SDK," a Lambda FAQ states. "Run your Java compiler tool on your source files and include the AWS SDK 1.9 or later with transitive dependencies on your classpath." Further guidance is provided for Authoring Lambda Functions in Java. Barr also provided some details about the two optional approaches for authoring Lambda functions, using a low-level stream-based model or a higher-level model leveraging "plain old Java objects" or Java primitives for the input and output objects.

Barr said support for additional programming languages is on tap.

In the Lambda pay-as-you-go pricing model, developers are charged for the number of requests generated and for the amount of code execution time. A free tier includes 1 million monthly requests and 400,000 "GB-seconds" of monthly compute time.

About the Author

David Ramel is an editor and writer for Converge360.

Featured

Subscribe on YouTube