Create Java AWS Lambda using Maven

Maven Lambda Java AWS

Maven Project setup

In the pom.xml, you will need to update the build settings of the project. Add the following maven config:

    <packaging>jar</packaging>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.2</version>
                <configuration>
                    <createDependencyReducedPom>false</createDependencyReducedPom>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

AWS Lambda Dependencies

In order to write lambdas in Java in a Maven project, the lambda dependency will need to be added to the pom.xml

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-lambda-java-core</artifactId>
    <version>1.2.0</version>
</dependency>

AWS DynamoDB Dependencies

It is highly likely that the lambda will require access to a data source such as DynamoDB. The DynamoDB dependency will need to be added to the pom.xml

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-dynamodb</artifactId>
    <version>1.11.744</version>
</dependency>

You may also like...

1 Response

  1. 2nd July 2020

    […] you enjoyed this article you will also find this article […]

Leave a Reply

Your email address will not be published. Required fields are marked *