> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/feature-management-experimentation/new-to-fme/sdks-and-customer-deployed-components/examples/java-sdk-aws-lambda.md).

# Deploy Java SDK in AWS Lambda

Learn how to deploy Java SDK code to an AWS Lambda function.

This page provides information on how to deploy Java SDK code in AWS Lambda services.

## Before you begin

* Use similar Java SDK code as in the [Java SDK example](https://github.com/Split-Community/Split-SDKs-Examples/tree/main/Java-SDK).
* AWS Lambda supports Java 8 runtime only, so ensure you use JDK 1.8.

## Step-by-step Guide

1. **Add AWS Lambda dependency**

   In the `pom.xml` file of the downloaded project, add the following inside the `<dependencies>` block:

   ```xml
   <dependency>
   <groupId>com.amazonaws</groupId>
   <artifactId>aws-lambda-java-core</artifactId>
   <version>1.0.0</version>
   </dependency>
   ```
2. **Update your Java class**
   * Open `SplitSDK_Sample.java`
   * Add these imports at the top:

     ```java
     import com.amazonaws.services.lambda.runtime.Context;
     import com.amazonaws.services.lambda.runtime.RequestHandler;
     ```
   * Modify the class declaration:

     ```java
     public class SplitSDK_Sample implements RequestHandler<Object, String> {
     ```
3. **Move your main method code into handleRequest**

   Replace the `main` method code with the following `handleRequest` method:

   ```java
   @Override
   public String handleRequest(Object input, Context context) {
      String myinput = input.toString();
      System.out.print("Input: " + myinput + "\n\n");
      HashMap<String, String> mapInput = (HashMap<String, String>) input;
      String userId = mapInput.get("key1");
      String treatment = "";
      try {
         MySplit split = new MySplit("API KEY");
         treatment = split.GetSplitTreatment(userId, "Split Name");             
         System.out.print("Treatment: " + treatment + "\n\n");
         split.Destroy();
      } catch (Exception e) {
         System.out.print("Exception: " + e.getMessage());
      }
      return treatment;
   }
   ```
4. **Build your project**

   * In Eclipse, select **Project** → **Build Project**, and ensure no build errors.
   * Right-click your project in Project Explorer → **Export**.

     ![](https://1473625385-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrT2RGHAjtBTaObzchfpb%2Fuploads%2Fgit-blob-4e1b586d0d2b03ea2b07051797c30a7757efe050%2Faws-5.png?alt=media)
   * Choose **Runnable JAR file** → **Next**.

     ![](https://1473625385-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrT2RGHAjtBTaObzchfpb%2Fuploads%2Fgit-blob-293115f790b2d177cae2c24505d4914630e05481%2Faws-6.png?alt=media)
   * Specify JAR location and name.
   * Select **Extract required libraries into generated JAR** → **Finish**.

   ![](https://1473625385-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrT2RGHAjtBTaObzchfpb%2Fuploads%2Fgit-blob-c2f2d38db1b079d7dcafcdbfa5719ef12a444cb3%2Faws-7.png?alt=media)
5. **Deploy to AWS Lambda**

   ![](https://1473625385-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrT2RGHAjtBTaObzchfpb%2Fuploads%2Fgit-blob-759d6a44032cf4d3ebf37c8dcd04da093f89daa4%2Faws-8.png?alt=media)

   * Login to AWS Console
   * Go to **Lambda** → **Functions**
   * Click **Create function**
   * Choose **Author from scratch**
   * Select **Java 8** runtime
   * Give your function a name
   * Click **Create function**
   * Under **Function code**, upload your generated JAR file and save.

     ![](https://1473625385-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrT2RGHAjtBTaObzchfpb%2Fuploads%2Fgit-blob-ccffaa977fdebbdf9e30db0d16643b9aba0416a1%2Faws-9.png?alt=media)
6. **Configure test event**

   ![](https://1473625385-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrT2RGHAjtBTaObzchfpb%2Fuploads%2Fgit-blob-eaed3806f4867a6cd2a5b963d678e27e546f48b9%2Faws-10.png?alt=media)

   * In the Lambda console, select **Configure test events**
   * Use the **Hello World** template
   * Set a value for key1 that matches the user ID your Lambda function will use.
   * Name and create the event

   ![](https://1473625385-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrT2RGHAjtBTaObzchfpb%2Fuploads%2Fgit-blob-3721b8766035f2a7cd163110f7f584df5d7b6333%2Faws-3.png?alt=media)
7. **Set Lambda handler**
   * In the **Function code** section, set the handler to:

     ```
     sample.SplitSDK_Sample::handleRequest
     ```

     ![](https://1473625385-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrT2RGHAjtBTaObzchfpb%2Fuploads%2Fgit-blob-9da31587645a1e29ab6d03284bc693723976a712%2Faws-12.png?alt=media)
   * Click **Save**.
8. **Test your Lambda function**

   ![](https://1473625385-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrT2RGHAjtBTaObzchfpb%2Fuploads%2Fgit-blob-a23c81f9e1b1e301ccd7417fb8040810a92da24e%2Faws-13.png?alt=media)

   * Click **Test**.
   * You should see the expected treatment value as output.
   * Logs will show debug information.

Download the [example project](https://drive.google.com/file/d/1iwl7u5ohAAx4PawuIw_gWb6kY_3Gfhs-/view?usp=sharing).

{% @harness-feedback/feedback %}
