How to Configure Eclipse/STS for AWS Lambda Java Development with the AWS Toolkit for Eclipse

Skip a trip to the AWS Management Console – Work with Lambda directly from your IDE instead!

In our previous posts, I introduced the building blocks of the Amazon API Gateway and AWS Lambda and their functionality. I am a Java developer and sometimes I need to test my code within my IDE (e.g. Eclipse or SpringSource Tool Suite) which is standard for our application.

In this blog post, I will present the configurations and examples of how to run AWS Lambda code from STS. You’ll be able to do this without taking a trip the AWS Management Console (though you may of course still need to sometimes). We’ll be using the AWS Toolkit for Eclipse.

Need a primer in AWS Lambda? Cloud Academy offers a suite of Lambda resources to get you started:

AWS Lambda Training

Let’s get going!

I have a Windows laptop with STS-3.7.3 based on Eclipse-4.5.2. We should install the AWS Toolkit for Eclipse before we dive any deeper. If you have the Toolkit for Eclipse, please skip the below step.

Install the AWS Toolkit for Eclipse:

  1. As pre-requisite, you should have an AWS account and sufficient privileges to execute Lambda and other services.
  2. You’ll need STS-3.7.3 or Eclipse IDE 3.6+.
  3. In Eclipse or STS, open help and then Install New Software.
  4. In next window, enter https://aws.amazon.com/eclipse in the text box labeled “Work with” at the top of the dialog. Press Add button and in the dialog box enter “AWS Toolkit” or any name that you are comfortable with but signifies it is the AWS Toolkit. Press OK.AWS Toolkit for Eclipse
  5. It will take some time to fetch all the required tools from the “Location” mentioned above and once the Name box populated, press Select All. Click Next.

AWS Toolkit for Eclipse
6. The installation will take a bit of time (depending on your internet bandwidth).
AWS Toolkit for Eclipse
7. The above items will be installed. Follow the instruction path by clicking the “Next” button, and you are done.
8. Once you restart your STS/Eclipse, you’ll notice the AWS Icon in the menu bar. Click on that icon, provide your AWS Credentials, and you are ready to go. You can see what services and which regions you have access to by reviewing the AWS Explorer in STS. As I am admin of my AWS Account, I have the following screen.

AWS Toolkit for Eclipse
(AWS Explorer)

Create the Project for AWS Lambda:

  1. Create AWS Lambda Java Project from AWS Toolkit.

AWS Lambda

       2. You might need to configure AWS SDK for Java which will be done in case you get the following error:

AWS Lambda

3. The configuration screen is as follows:

AWS Lambda

4. The project configuration for our example is as follows:

AWS Lambda

  • Project Name: AWSLambdaDemo
  • Package Name: aws.lambda.demo
  • Class Name: DemoLambdaFunctionHandler
  • Input Type: S3Event
  • Output Type: Object

Click on finish to get the welcome page in STS for instruction. Remove any kind of dependency that might be causing an error message. Add two more jars for future examples and use. Acquire the following jars through maven or download them from github/maven repo:

5.  Below you can see the output of the project:
AWS Lambda
6. The generated artifacts are as follows:

  • The DemoLambdaFunctionHandler class implements of the RequestHandler interface that defines the Lambda function you need to implement.
  • The DemoLambdaFunctionHandlerTest class is for the unit tests cases.
  • The TestContext class is an implementation of the Context interface, which acts as a parameter for the Lambda function.
  • The TestUtils class will be used for parsing the JSON file.
  • A sample S3 event source configuration file, s3-event.put.json for testing.

7. Implement the Lambda function inside handleRequest(..) method. In this sample implementation of the Lambda function, it returns the bucket name from the S3 Event.

package com.aws.lambda.demo;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.S3Event;
public class DemoLambdaFunctionHandler implements RequestHandler<S3Event, Object> {
    @Override
    public Object handleRequest(S3Event input, Context context) {
        context.getLogger().log("Input: " + input);
        return input.getRecords().get(0).getS3().getBucket().getName();
    }
}

8. Test the Lambda function test case using JUnit.
9. Upload & Run the Lambda function as below:
AWS Lambda functions
10 . Provide function name as S3DemoLambdaFunction and configure the function. Create the bucket if you do not have one.
AWS Lambda functions

AWS Lambda functions
11. I had an existing Lambda role as AWSLambdaRole which was populated here. I previously created the bucket “cplambdatestbucket“, which is shown below. I have reduced the memory print to 256 MB, instead of the default of 512 MB. That was our goal.
Our goal was to complete all AWS Console activities without visiting AWS Management Console or AWS CLI and I believe we have done this.
Allow some time to upload the function and click on Run function on AWS Lambda.
AWS Lambda functions

12. It will ask for the Lambda Function Input which, is obviously our s3-event.put.json file which is auto-populated.
AWS Lambda functions
13. Click on invoke. We are expecting to print the bucket name. The output we receive shows below:
AWS Lambda functions
14.  Go to the AWS Management Lambda Console to verify if the function is indeed available. Here is the snapshot:
AWS Lambda functions
15. Verify the authenticity of the Eclipse-based Lambda function with a test.
Select S3 Put as a sample event template, and test. The bucket name is “sourcebucket”. Click on Test. The output should appear as below. Notice that it takes the configured memory size 256MB rather than the default 512MB.
AWS Lambda functions

Conclusion

Java developers often use their IDE the same way they use Eclipse or STS, or Netbeans. These IDEs offer a great method of coding. They assist in maintaining versions using SVN/ Git, CI/CD with Jenkins and deploying programs directly to any web servers or cloud, like AWS, PWS, etc. from one place.
As Lambda executes code without servers (Lambda is basically PaaS of AWS), developers benefit by shortening their development and deployment lifecycle in the cloud. More efficiency and greater use of resources builds higher productivity and better projects. 
This is a simple example of how the AWS Toolkit is configured and used for Lambda function invocation without opening the Lambda service page. You should certainly try some more examples and explore ways they help increase your productivity as long as you are using Java as your development language.

Get Started with Cloud Academy Today!

Cloud Academy offers a free 7-day trial subscription where you can follow a Learning Path toward your ultimate career goals or certifications. If you’re new to Java, you can begin with the Introduction to Java Learning Path. To take your skills to the next level, advanced programmers can begin with our Advanced Java Learning Path.

Cloud Academy has Hands-on Labs that grant you access to real development environments without leaving the Cloud Academy site. There are video courses and quizzes for reinforcing knowledge. This is a complete eLearning system and a great community. Check it out and provide feedback.

 

Avatar

Written by

Chandan Patra

Cloud Computing and Big Data professional with 10 years of experience in pre-sales, architecture, design, build and troubleshooting with best engineering practices. Specialities: Cloud Computing - AWS, DevOps(Chef), Hadoop Ecosystem, Storm & Kafka, ELK Stack, NoSQL, Java, Spring, Hibernate, Web Service


Related Posts

Avatar
Stuart Scott
— October 16, 2019

AWS Security: Bastion Host, NAT instances and VPC Peering

Effective security requires close control over your data and resources. Bastion hosts, NAT instances, and VPC peering can help you secure your AWS infrastructure. Welcome to part four of my AWS Security overview. In part three, we looked at network security at the subnet level. This ti...

Read more
  • AWS
Avatar
Sudhi Seshachala
— October 9, 2019

Top 13 Amazon Virtual Private Cloud (VPC) Best Practices

Amazon Virtual Private Cloud (VPC) brings a host of advantages to the table, including static private IP addresses, Elastic Network Interfaces, secure bastion host setup, DHCP options, Advanced Network Access Control, predictable internal IP ranges, VPN connectivity, movement of interna...

Read more
  • AWS
  • best practices
  • VPC
Avatar
Stuart Scott
— October 2, 2019

Big Changes to the AWS Certification Exams

With AWS re:Invent 2019 just around the corner, we can expect some early announcements to trickle through with upcoming features and services. However, AWS has just announced some big changes to their certification exams. So what’s changing and what’s new? There is a brand NEW ...

Read more
  • AWS
  • Certifications
Alisha Reyes
Alisha Reyes
— October 1, 2019

New on Cloud Academy: ITIL® 4, Microsoft 365 Tenant, Jenkins, TOGAF® 9.1, and more

At Cloud Academy, we're always striving to make improvements to our training platform. Based on your feedback, we released some new features to help make it easier for you to continue studying. These new features allow you to: Remove content from “Continue Studying” section Disc...

Read more
  • AWS
  • Azure
  • Google Cloud Platform
  • ITIL® 4
  • Jenkins
  • Microsoft 365 Tenant
  • New content
  • Product Feature
  • Python programming
  • TOGAF® 9.1
Avatar
Stuart Scott
— September 27, 2019

AWS Security Groups: Instance Level Security

Instance security requires that you fully understand AWS security groups, along with patching responsibility, key pairs, and various tenancy options. As a precursor to this post, you should have a thorough understanding of the AWS Shared Responsibility Model before moving onto discussi...

Read more
  • AWS
  • instance security
  • Security
  • security groups
Avatar
Jeremy Cook
— September 17, 2019

Cloud Migration Risks & Benefits

If you’re like most businesses, you already have at least one workload running in the cloud. However, that doesn’t mean that cloud migration is right for everyone. While cloud environments are generally scalable, reliable, and highly available, those won’t be the only considerations dri...

Read more
  • AWS
  • Azure
  • Cloud Migration
Joe Nemer
Joe Nemer
— September 12, 2019

Real-Time Application Monitoring with Amazon Kinesis

Amazon Kinesis is a real-time data streaming service that makes it easy to collect, process, and analyze data so you can get quick insights and react as fast as possible to new information.  With Amazon Kinesis you can ingest real-time data such as application logs, website clickstre...

Read more
  • amazon kinesis
  • AWS
  • Stream Analytics
  • Streaming data
Joe Nemer
Joe Nemer
— September 6, 2019

Google Cloud Functions vs. AWS Lambda: The Fight for Serverless Cloud Domination

Serverless computing: What is it and why is it important? A quick background The general concept of serverless computing was introduced to the market by Amazon Web Services (AWS) around 2014 with the release of AWS Lambda. As we know, cloud computing has made it possible for users to ...

Read more
  • AWS
  • Azure
  • Google Cloud Platform
Joe Nemer
Joe Nemer
— September 3, 2019

Google Vision vs. Amazon Rekognition: A Vendor-Neutral Comparison

Google Cloud Vision and Amazon Rekognition offer a broad spectrum of solutions, some of which are comparable in terms of functional details, quality, performance, and costs. This post is a fact-based comparative analysis on Google Vision vs. Amazon Rekognition and will focus on the tech...

Read more
  • Amazon Rekognition
  • AWS
  • Google Cloud Platform
  • Google Vision
Alisha Reyes
Alisha Reyes
— August 30, 2019

New on Cloud Academy: CISSP, AWS, Azure, & DevOps Labs, Python for Beginners, and more…

As Hurricane Dorian intensifies, it looks like Floridians across the entire state might have to hunker down for another big one. If you've gone through a hurricane, you know that preparing for one is no joke. You'll need a survival kit with plenty of water, flashlights, batteries, and n...

Read more
  • AWS
  • Azure
  • Google Cloud Platform
  • New content
  • Product Feature
  • Python programming
Joe Nemer
Joe Nemer
— August 27, 2019

Amazon Route 53: Why You Should Consider DNS Migration

What Amazon Route 53 brings to the DNS table Amazon Route 53 is a highly available and scalable Domain Name System (DNS) service offered by AWS. It is named by the TCP or UDP port 53, which is where DNS server requests are addressed. Like any DNS service, Route 53 handles domain regist...

Read more
  • Amazon
  • AWS
  • Cloud Migration
  • DNS
  • Route 53
Alisha Reyes
Alisha Reyes
— August 22, 2019

How to Unlock Complimentary Access to Cloud Academy

Are you looking to get trained or certified on AWS, Azure, Google Cloud Platform, DevOps, Cloud Security, Python, Java, or another technical skill? Then you'll want to mark your calendars for August 23, 2019. Starting Friday at 12:00 a.m. PDT (3:00 a.m. EDT), Cloud Academy is offering c...

Read more
  • AWS
  • Azure
  • cloud academy content
  • complimentary access
  • GCP
  • on the house