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
Please enter at least three characters to search
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

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

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

  • Can You Run a MariaDB Cluster on a $150 Kubernetes Lab? I Gave It a Shot
  • Event-Driven Architectures: Designing Scalable and Resilient Cloud Solutions
  • How To Introduce a New API Quickly Using Quarkus and ChatGPT
  • Navigating the LLM Landscape: A Comparative Analysis of Leading Large Language Models
  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.4K 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
Oops! Something Went Wrong

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
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!