> 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

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

## Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

* 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 <a href="#step-by-step-guide" id="step-by-step-guide"></a>

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**.

     ![](/files/1PZadfuKd8rrbAdJcvIJ)
   * Choose **Runnable JAR file** → **Next**.

     ![](/files/u2IA3wxcAorfEOfoBpwQ)
   * Specify JAR location and name.
   * Select **Extract required libraries into generated JAR** → **Finish**.

   ![](/files/noUFKpUS0hia9DlLdLBY)
5. **Deploy to AWS Lambda**

   ![](/files/oB1ZHKyl8azMewnScblc)

   * 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.

     ![](/files/TjvXL5tC6g7bGpilHCjo)
6. **Configure test event**

   ![](/files/rL05jhMD7lMb2Dh6sD4t)

   * 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

   ![](/files/FLzHzayOjBfDt4v8yiCh)
7. **Set Lambda handler**
   * In the **Function code** section, set the handler to:

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

     ![](/files/UJl7KHlB2yk75JUh4DPF)
   * Click **Save**.
8. **Test your Lambda function**

   ![](/files/566p7c1jQi1AXwppRyBL)

   * 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).
