title: Passing context / authorisation with cloudfront to lambda
body: <p>This is bit tricky situation I got into here,
  I set up a lambda function &amp; API gateway, then I setup cloudfront over API gateway for faster processing and achieving benefit of all the endpoint nodes provided by AWS [It should take more time using cloudfront on top of API gateway service but I am getting better result with cloudfront layer on top of it, maybe DNS resolution and AWS internal infrastructure is better]</p>
  
  <p>I setup a JAVA function inside lambda which is working perfectly fine, but I want to use Context of request maker in lambda function</p>
  
  <pre><code>public String handleRequest(UserPOJO input, Context context) {
  }
  </code></pre>
  
  <p>If I make direct lambda function request I can achieve that but it's taking too much time executing direct lambda from my Android client, also I don't find it good to expose those details, and with cloudfront I am not sure what headers should I send so that lambda detects it's cognito role and ID using <code>context.getIdentity().getIdentityId();</code> in lambda.</p>
  
  <p>If someone understands my problem here and elaborate it better for other I will be glad, it is very complex to explain the problem.</p>
  
  <p>Technically</p>
  
  <ol>
  <li><p>I can make execution of lambda function directly with cognito credential provider authentication but Very slow</p></li>
  <li><p>Can make API gateway request which cognito credential provider authentication, speed is better than direct lambda execution</p></li>
  <li><p>Can make cloudfront request but stuck where I don't know how can I use cognito credential provider authorisation while making the request. Seemed faster than API gateway.</p></li>
  </ol>
  
  <p>Thanks. :)</p>