Skip to main content

Write Your AWS Lambda Functions in Java

AWS Lambda is an Amazon Web Services compute service that makes it easy for you to build applications that respond quickly to new information. AWS Lambda runs your code in response to specific events. It is up to you to choose the type of events, however, here are some examples of the kinds of events that could be made to trigger a Lambda function:

  • Image uploads
  • In-app activity; website clicks
  • Output from connected devices
  • Product purchases

AWS Lambda can be used to extend other AWS services with custom logic. You can even use it to create a dynamic back-end that operates at AWS scale, performance, and security. Not only that, you can easily create discrete, event-driven applications that execute only when needed and scale automatically from a few requests per day to thousands per second.

AWS Lambda works by running your code on a high-availability compute infrastructure and performs all the administration of the compute resources, which includes:

  • Server and operating system maintenance
  • Capacity provisioning and automatic scaling
  • Code and security patch deployment
  • Code monitoring and logging

What’s changed with AWS Lambda

Up until one week ago, the only solution available for developers to write their Lambda functions was in Node.js, which is a JavaScript derivative specifically designed for use in server-side applications. However,  AWS announced that you can now write your Lambda functions in Java.

AWS also has plans to continue adding language options for Lambda functions sometime in the near future. Naturally, all of our existing development tools can of course still be used.

If you are already familiar with uploading Node.js deployment packages to Lambda, you will already know that they are limited to fifty MB. This limit will be true for your Java code as well. Some other things that you need to be aware of if you intend to utilize this new functionality include:

  • You must create a ZIP or JAR file that contains your compiled code (CLASS files) and any desired JAR files.
  • Your handler functions should be stored in the usual Java directory structure (e.g.com/mypackage/MyHandler.class).
  • Your JAR files must be directly inside of a lib subdirectory.
  • You must specify a runtime of “java8″ when you upload your ZIP file.
  • If you implemented one of the handler interfaces, you will need to provide the class name, or otherwise, provide the fully qualified method reference, like:
    com.mypackage.LambdaHandler::functionHandler

AWS Lambda and Cloud Academy

If you’re not yet that familiar with Lambda, Cloud Academy has some excellent learning resources to help:

Cloud Academy’s Understanding AWS Lambda course provides a complete introduction to AWS Lambda. Lambda is not a particularly complex service, but setting IAM roles and security groups might be tricky. This tutorial, written by our expert Cloud Solutions Architect Kevin Felitchko, will help you get started, and provide an interesting and practical use-case.

Cloud Academy also has a hands-on lab on Automated static site generation using AWS S3 and Lambda. This intermediate-level lab will guide you through the steps necessary to process content, host it on S3, and manage Lambda’s access to your other AWS resources.

We’ve also got a set of self-testing questions in our Lambda Quiz to help you assess your overall understanding of the service.

Further Reading

The Official AWS Announcement
Authoring Lambda Functions in Java

Avatar

Written by

Michael Sheehy

I have been UNIX/Linux System Administrator for the past 15 years and am slowly moving those skills into the AWS Cloud arena. I am passionate about AWS and Cloud Technologies and the exciting future that it promises to bring.

Related Posts

Sam Ghardashem
Sam Ghardashem
— May 15, 2019

Aviatrix Integration of a NextGen Firewall in AWS Transit Gateway

Learn how Aviatrix’s intelligent orchestration and control eliminates unwanted tradeoffs encountered when deploying Palo Alto Networks VM-Series Firewalls with AWS Transit Gateway.Deploying any next generation firewall in a public cloud environment is challenging, not because of the f...

Read more
  • AWS
Joe Nemer
Joe Nemer
— May 3, 2019

AWS Config Best Practices for Compliance

Use AWS Config the Right Way for Successful ComplianceIt’s well-known that AWS Config is a powerful service for monitoring all changes across your resources. As AWS Config has constantly evolved and improved over the years, it has transformed into a true powerhouse for monitoring your...

Read more
  • AWS
  • Compliance
Avatar
Francesca Vigliani
— April 30, 2019

Cloud Academy is Coming to the AWS Summits in Atlanta, London, and Chicago

Cloud Academy is a proud sponsor of the 2019 AWS Summits in Atlanta, London, and Chicago. We hope you plan to attend these free events that bring the cloud computing community together to connect, collaborate, and learn about AWS. These events are all about learning. You can learn how t...

Read more
  • AWS
  • AWS Summits
Paul Hortop
Paul Hortop
— April 2, 2019

How to Monitor Your AWS Infrastructure

The AWS cloud platform has made it easier than ever to be flexible, efficient, and cost-effective. However, monitoring your AWS infrastructure is the key to getting all of these benefits. Realizing these benefits requires that you follow AWS best practices which constantly change as AWS...

Read more
  • AWS
  • Monitoring
Joe Nemer
Joe Nemer
— April 1, 2019

AWS EC2 Instance Types Explained

Amazon Web Services’ resource offerings are constantly changing, and staying on top of their evolution can be a challenge. Elastic Cloud Compute (EC2) instances are one of their core resource offerings, and they form the backbone of most cloud deployments. EC2 instances provide you with...

Read more
  • AWS
  • EC2
Avatar
Nitheesh Poojary
— March 26, 2019

How DNS Works – the Domain Name System (Part One)

Before migrating domains to Amazon's Route53, we should first make sure we properly understand how DNS worksWhile we'll get to AWS's Route53 Domain Name System (DNS) service in the second part of this series, I thought it would be helpful to first make sure that we properly understand...

Read more
  • AWS
Avatar
Stuart Scott
— March 14, 2019

Multiple AWS Account Management using AWS Organizations

As businesses expand their footprint on AWS and utilize more services to build and deploy their applications, it becomes apparent that multiple AWS accounts are required to manage the environment and infrastructure.  A multi-account strategy is beneficial for a number of reasons as ...

Read more
  • AWS
  • Identity Access Management
Avatar
Sanket Dangi
— February 11, 2019

WaitCondition Controls the Pace of AWS CloudFormation Templates

AWS's WaitCondition can be used with CloudFormation templates to ensure required resources are running.As you may already be aware, AWS CloudFormation is used for infrastructure automation by allowing you to write JSON templates to automatically install, configure, and bootstrap your ...

Read more
  • AWS
  • CloudFormation
Badrinath Venkatachari
Badrinath Venkatachari
— February 1, 2019

10 Common AWS Mistakes & How to Avoid Them

Massive migration to the public cloud is changing architecture patterns, operating principles, and governance models. That means new approaches are vital to get a handle on soaring cloud spend. Because the cloud’s short-term billing cycles call for financial discipline, you must empower...

Read more
  • AWS
  • Operations
Avatar
Andrew Larkin
— January 24, 2019

The 9 AWS Certifications: Which is Right for You and Your Team?

As companies increasingly shift workloads to the public cloud, cloud computing has moved from a nice-to-have to a core competency in the enterprise. This shift requires a new set of skills to design, deploy, and manage applications in cloud computing.As the market leader and most ma...

Read more
  • AWS
  • AWS Certifications
Avatar
Andrew Larkin
— January 15, 2019

2018 Was a Big Year for Content at Cloud Academy

As Head of Content at Cloud Academy I work closely with our customers and my domain leads to prioritize quarterly content plans that will achieve the best outcomes for our customers.We started 2018 with two content objectives: To show customer teams how to use Cloud Services to solv...

Read more
  • AWS
  • Azure
  • Cloud Computing
  • Google Cloud Platform
Avatar
Jeremy Cook
— November 29, 2018

Amazon Elastic Inference – GPU Acceleration for Faster Inferencing

“Add GPU acceleration to any Amazon EC2 instance for faster inference at much lower cost (up to 75% savings)”So you’ve just kicked off the training phase of your multilayered deep neural network. The training phase is leveraging Amazon EC2 P3 instances to keep the training time to a...

Read more
  • AWS
  • Elastic Inference
  • re:Invent 2018