title: AWS Lambda + Spring, how to load application.yml
body: <p>I have problem with customizing API gateway domain, for my restful app deployed on AWS lambda. Customized domain, works this way, that depending on basePath it chooses different APIs which finally touches Lambda. For example:</p>
  
  <p><code>api.mycustomdomain.com/view/ping</code> -> goes to application <code>view</code> with path <code>/view/ping</code>
  <code>api.mycustomdomain.com/admin/ping</code> -> goes to application <code>admin</code> with path <code>/admin/ping</code></p>
  
  <p>I am using this example as boilerplate: <a href="https://github.com/awslabs/aws-serverless-java-container/tree/master/samples/spring/pet-store" rel="nofollow noreferrer">https://github.com/awslabs/aws-serverless-java-container/tree/master/samples/spring/pet-store</a></p>
  
  <p>What I would like to achieve is handler which depending on <code>Host</code> header strips prefix from request path.</p>
  
  <p>I have prepared following application.yml file:</p>
  
  <pre><code>server:
    contextPath: "/view"
    productionHost: "api.mycustomdomain.com"
  </code></pre>
  
  <p>The problem/question is. How can I now load those into my Lambda function? Here is my naive try:</p>
  
  <pre><code>public class LambdaHandler implements RequestHandler&lt;AwsProxyRequest, AwsProxyResponse&gt; {
      SpringLambdaContainerHandler&lt;AwsProxyRequest, AwsProxyResponse&gt; handler;
      boolean isinitialized = false;
  
      @Value("${server.contextPath}")
      private String prefix;
  
      @Value("${server.productionHost}")
      private String productionHost;
  
      public AwsProxyResponse handleRequest(AwsProxyRequest awsProxyRequest, Context context) {
          if(awsProxyRequest.getHeaders().get("Host").equals(productionHost))
              awsProxyRequest.setPath(awsProxyRequest.getPath().substring(prefix.length()));
  
          if (!isinitialized) {
              isinitialized = true;
              try {
                  handler = SpringLambdaContainerHandler.getAwsProxyHandler(PingPongApp.class);
              } catch (ContainerInitializationException e) {
                  e.printStackTrace();
                  return null;
              }
          }
          return handler.proxy(awsProxyRequest, context);
      }
  }
  </code></pre>
  
  <p>Obviously this doesn't work, LambdaHandler is working out of Spring context.</p>
  
  <p>Any ideas how can I deal with that?</p>