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
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

How does AI transform chaos engineering from an experiment into a critical capability? Learn how to effectively operationalize the chaos.

Data quality isn't just a technical issue: It impacts an organization's compliance, operational efficiency, and customer satisfaction.

Are you a front-end or full-stack developer frustrated by front-end distractions? Learn to move forward with tooling and clear boundaries.

Developer Experience: Demand to support engineering teams has risen, and there is a shift from traditional DevOps to workflow improvements.

Related

  • Building Scalable Data Lake Using AWS
  • Building a Scalable ML Pipeline and API in AWS
  • Breaking AWS Lambda: Chaos Engineering for Serverless Devs
  • AWS Step Functions Local: Mocking Services, HTTP Endpoints Limitations

Trending

  • Modernizing Financial Systems: The Critical Role of Cloud-Based Microservices Optimization
  • Why Whole-Document Sentiment Analysis Fails and How Section-Level Scoring Fixes It
  • Apache Doris and DeepSeek: Redefining Intelligent Data Analytics
  • Smarter IoT Systems With Edge Computing and AI
  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 user avatar
Ajitesh Kumar
·
Mar. 16, 18 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
24.5K Views

Join the DZone community and get the full member experience.

Join For Free

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, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Building Scalable Data Lake Using AWS
  • Building a Scalable ML Pipeline and API in AWS
  • Breaking AWS Lambda: Chaos Engineering for Serverless Devs
  • AWS Step Functions Local: Mocking Services, HTTP Endpoints Limitations

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: