DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • End-to-End Event Streaming With Kafka, Spring Boot and AWS SQS/SNS (Production-Ready Code Guide)
  • AWS Bedrock: The Future of Enterprise AI
  • Understanding Custom Authorization Mechanisms in Amazon API Gateway and AWS AppSync
  • AWS Transfer Family SFTP Setup (Password + SSH Key Users) Using Lambda Identity Provider + S3

Trending

  • Part 1: Building Governed MCP Tool Services With Quarkus LangChain4j and Goose
  • When RabbitMQ Accepts a Message but Does Not Route It to a Queue
  • Fix the Target, Precompute Once: A Backend-Free Word-Ladder Solver With a BFS Distance Field
  • Why Vulnerability Management Fails Without Reliable Asset Data

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Creating an AWS Lambda Deployment JAR Using Maven

Creating an AWS Lambda Deployment JAR Using Maven

Bringing your Java to the cloud? Here are a couple of ways you can get a deployment JAR up and ready for AWS Lambda functions.

By 
Ajitesh Kumar
·
Mar. 16, 18 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
25.2K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

One key aspect of AWS Lambda functions (with Java) is creating deployment packages (JAR or ZIP files) for uploading/deploying on the AWS Lambda service. In this post, you will learn different ways in which you can create a deployment JAR file for AWS Lambda projects using Maven. We will look at:

  • Deployment JAR using Maven and Eclipse IDE
  • Deployment JAR using Maven and the command prompt

I recommend using the "Maven and command prompt" technique for creating your deployment JAR package, but we will cover both methods.

Before getting started, download the AWS Toolkit for Eclipse from the Eclipse Marketplace. Here is the information on getting set up with AWS Toolkit for Eclipse.

Deployment JAR using Maven and Eclipse IDE

The following are steps required to create an AWS Lambda deployment JAR file using Eclipse IDE and Maven:

  • Create an AWS Lambda Java Project using Eclipse > New > AWS Lambda Java Project
  • You will be asked to provide project details, including input type — which is an Amazon services trigger used to invoke the Lambda function.
  • Create your function. The following is a sample AWS Lambda function whose input type is an SNS event.
    public class LambdaFunctionHandler implements RequestHandler<SNSEvent, String> {
        @Override
        public String handleRequest(SNSEvent event, Context context) {
            context.getLogger().log("Received event: " + event);
            String message = event.getRecords().get(0).getSNS().getMessage();
            context.getLogger().log("From SNS: " + message);
            return message;
        }
    }

  • Follow the steps mentioned in Creating a Deployment JAR Package Using Maven and Eclipse IDE to create the deployable JAR file. Primarily, the following needs to be done: 
    • From the context menu for the project in Package Explorer, click Run As > Maven Build…. In the Edit Configuration window, type package in the Goals text field and submit by clicking RUN.
    • This step is needed for creating a standalone JAR file that contains the compiled customer code and the resolved dependencies from the pom.xml. Add the maven-shade-plugin plugin by right clicking on pom.xml and clicking on Maven > Add Plugin and adding following details: 
      • Group Id: org.apache.maven.plugins
      • Artifact Id: maven-shade-plugin
      • Version: 2.3
    • From the context menu for the project in Package Explorer, click Run As > Maven Build…. In the Edit Configuration window, type package shade:shade in the Goals text field and submit by clicking RUN.
  • You would see two JAR files based on your artifactId name and version. For example, if your artifactId name is demo, you would see demo-1.0.0.jar and original-demo-1.0.0.jar.
  • Pick the file named as “demo-1.0.0.jar” for deploying as your AWS Lambda deployment JAR file.
  • Upload the appropriate JAR file, as mentioned above in AWS S3 (recommended).
  • Provide the link to the JAR file when creating Lambda functions.

Deployment JAR Using Maven Only (Without Eclipse IDE)

  • Place the following maven-shade-plugin detail in your pom.xml:
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.0.0</version>
        <configuration>
            <createDependencyReducedPom>false</createDependencyReducedPom>
        </configuration>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>shade</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

  • Execute: 
    mvn package

  • You should see two JAR files based on your artifactId name and version. For example, if your artifactId name is demo, you would see demo-1.0.0.jar and original-demo-1.0.0.jar.
  • Pick the file named as “demo-1.0.0.jar” file for deployment on AWS Lambda.
  • Upload the appropriate JAR file in AWS S3 (recommended).
  • Provide the link to the JAR file when creating Lambda functions.

Further Reading/References

  • Creating a Deployment JAR Using Maven without any IDE (Java)
  • Creating a Deployment JAR Package Using Maven and Eclipse IDE 

Summary

In this post, you learned about creating a deployment JAR package for AWS Lambda using Maven.

Did you find this article useful? Do you have any questions or suggestions about this article in relation to techniques used for creating deployment JARs for AWS Lambda? Leave a comment and ask your questions, and I shall do my best to address your queries.

AWS AWS Lambda JAR (file format) Apache Maven

Published at DZone with permission of Ajitesh Kumar. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • End-to-End Event Streaming With Kafka, Spring Boot and AWS SQS/SNS (Production-Ready Code Guide)
  • AWS Bedrock: The Future of Enterprise AI
  • Understanding Custom Authorization Mechanisms in Amazon API Gateway and AWS AppSync
  • AWS Transfer Family SFTP Setup (Password + SSH Key Users) Using Lambda Identity Provider + S3

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook