title: How To Convert Java Lambda from AWS API Gateway to Load Balancer
body: <p>I have a Lambda function in Java which is invoked by AWS Api Gateway. The Lambda function accepts PolicyNo in request body and returns the same PolicyNo in response. Below is the Lambda code. </p>
  
  <pre><code>import com.amazonaws.services.lambda.runtime.Context;
  import com.amazonaws.services.lambda.runtime.LambdaLogger;
  import com.amazonaws.services.lambda.runtime.RequestHandler;
  import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
  import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
  
  public class AssuranceDataRequestHandler implements RequestHandler&lt;APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent&gt; {
  
      public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent apiGatewayProxyRequestEvent, Context context) {
          APIGatewayProxyResponseEvent apiGatewayProxyResponseEvent = new APIGatewayProxyResponseEvent();
          try {
              LambdaLogger logger = context.getLogger();
              final AmazonCloudWatch cw = AmazonCloudWatchClientBuilder.defaultClient();
              apiGatewayProxyRequestEvent.getPathParameters();
              String requestString = apiGatewayProxyRequestEvent.getBody();
              logger.log("API Gateway requestString : " + requestString);
              JSONParser parser = new JSONParser();
              JSONObject requestJsonObject = (JSONObject) parser.parse(requestString);
              String policyNo = null;
  
              if (requestJsonObject != null) {
                  if (requestJsonObject.get("policyNo") != null) {
                      policyNo = requestJsonObject.get("policyNo").toString();
                  }        
              }
              PolicyNo policyNoBo = new PolicyNo();
              policyNoBo.setPolicyNo();
              ObjectMapper mapper = new ObjectMapper();
              try {
                  responseMessage = mapper.writeValueAsString(policyNoBo);
               /// responseMessage = new JSONObject(salesVideoResponse).toJSONString();
                System.out.println("ResultingJSONstring = " + responseMessage);
                //System.out.println(json);
              } catch (JsonProcessingException e) {
                 e.printStackTrace();
              }
              generateResponse(apiGatewayProxyResponseEvent, responseMessage);
          } catch (ParseException e) {
              e.printStackTrace();
          }
          return apiGatewayProxyResponseEvent;
      }
  
  
      private void generateResponse(APIGatewayProxyResponseEvent apiGatewayProxyResponseEvent, String requestMessage) {
          apiGatewayProxyResponseEvent.setHeaders(Collections.singletonMap("timeStamp", String.valueOf(System.currentTimeMillis())));
          apiGatewayProxyResponseEvent.setStatusCode(200);
          apiGatewayProxyResponseEvent.setBody(requestMessage);
      }
  }
  </code></pre>
  
  <p>I need to change this implementation to Load Balancer where below is the URL and I need to fetch PolicyNo from the url.</p>
  
  <pre><code>https://XXXXXXX/api/hk/health/policy/v1/policies/{policyNo}/coverage/benefit/
  </code></pre>
  
  <p>In summary, I need to convert my Lambda function to invoke from Load Balancer.</p>