News

AWS Cloud Adds Java for Event-Driven Lambda Functions

Amazon Web Services Inc. (AWS) yesterday announced that cloud developers can now use Java for writing Lambda functions, which provide event-driven functionality while taking care of needed compute resources.

Having been moved from a preview into production mode two months ago, the Lambda service has been getting enhancements, such as a synchronous invocation capability, that suit it for mobile back-ends and for building server-side infrastructure to back Web and Internet-of-Things (IoT) applications.

Now it supports Java, the first of more programming languages to be added to the mix.

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.

"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."

"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.

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.