Replace com.example.myapp with the full package namespace of your
application. Also replace myapp with your project name. This becomes
the name of the directory for your project.
This command creates a Maven project using the archetype templating toolkit. The
archetype generates the scaffolding for an AWS Lambda function handler project . This project
archetype is preconfigured to compile with Java SE 8 and includes a dependency to the version
of the SDK for Java 2.x specified with -DarchetypeVersion.
If you created your project using the AWS Lambda project archetype as
described previously, the configuration of the Java compiler is already done for you.
To verify that this configuration is present, start by opening the pom.xml file from the project folder you created (for example, myapp) when you executed the previous command. Look on lines 11 and 12 to see the Java compiler version setting for this Maven project, and the required inclusion of the Maven compiler plugin on lines 71-75.
If you create your project with a different archetype or by using another method, you must ensure that the Maven compiler plugin is part of the build and that its source and target properties are both set to 1.8 in the pom.xml file.
See the previous snippet for one way to configure these required settings.
Alternatively, you can configure the compiler configuration inline with the plugin declaration, as follows.
To use the AWS SDK for Java in your project, you need to declare it as a dependency in your project’s pom.xml file.
If you created your project using the project archetype as described previously, the
latest version of the SDK is already configured as a dependency in your project.
The archetype generates a BOM (bill of materials) artifact dependency for the
software.amazon.awssdk group id. With a BOM, you do not have to specify the
maven version for individual artifact dependencies that share the same group id.
If you created your Maven project in a different way, configure the latest version of the SDK for your project by ensuring that the pom.xml file contains the following.
Now that you have configured the SDK, you can add dependencies for one or more of the AWS SDK for Java modules to use in your project.
Although you can specify the version number for each component, you don’t need to
because you already declared the SDK version in the dependencyManagement section
using the bill of materials artifact. To load a different version of a given module, specify a
version number for its dependency.
If you created your project using the project archetype as described previously, your
project is already configured with multiple dependencies. These include dependences for
AWS Lambda function handlers and Amazon S3, as follows.
In the pom.xml example above, the dependencies are from different
groupIds. The s3 dependency is from
software.amazon.awssdk, whereas the aws-lambda-java-core
dependency is from com.amazonaws. The BOM dependency management configuration
affects artifacts for software.amazon.awssdk, so a version is needed for the
aws-lambda-java-core artifact.
For the development of Lambda function handlers using
the SDK for Java 2.x, aws-lambda-java-core is the correct dependency. However, if your
application needs to manage Lambda resources, using operations such as
listFunctions, deleteFunction, invokeFunction, and
createFunction, your application requires the following dependency.
software.amazon.awssdklambda
Note
The s3 dependency excludes the the netty-nio-client and
apache-client transitive dependencies. In place of either of those HTTP
clients, the archetype includes the url-connection-client dependency, which
helps reduce the startup latency for AWS Lambda
functions.
Add the modules to your project for the AWS service and features you need
for your project. The modules (dependencies) that are managed by the AWS SDK for Java
BOM are listed on the Maven central
repository.
Note
You can look at the pom.xml file from a code example to determine which
dependencies you need for your project. For example, if you’re interested in the
dependencies for the DynamoDB service, see this example from the AWS Code Examples Repository on GitHub. (Look for the
pom.xml file under /javav2/example_code/dynamodb.)
Build the entire SDK into your project
To optimize your application, we strongly recommend that you pull in only the components you need instead of the entire SDK. However, to build the entire AWS SDK for Java into your project, declare it in your pom.xml file, as follows.
software.amazon.awssdkaws-sdk-java2.X.X
Build your project
After you configure the pom.xml file, you can use Maven to build your project.
To build your Maven project from the command line, open a terminal or command prompt window, navigate to your project directory (for example, myapp), enter or paste the following command, then press Enter or Return.
mvn package
This creates a single .jar file (JAR) in the target directory (for example, myapp/target). This JAR contains all of the SDK modules you specified as dependencies in your pom.xml file.
Did this page help you? - Yes
Thanks for letting us know we're doing a good job!
If you've got a moment, please tell us what we did right so we can do more of it.
Did this page help you? - No
Thanks for letting us know this page needs work. We're sorry we let you down.
If you've got a moment, please tell us how we can make the documentation better.