title: AWS API Gatway (Proxy) with Lambda - Thworing internal server error
body: <p>I am working on a custom auth solution, I backend is on NODE (lambda) and calling that lambda by API gateway (it's a post-call).
  For every thin is working fine if I use no-Proxy APIs, but in my case in need to pass custom additional headers. And when I tried with prox it is not responding. (it look like Cognito async call takes time or response is not resolving)
  I am not sure I am missing some configuration or something wrong with code (code is working fine individual lambda and with API without Proxy).
  here is my Lambda code.</p>
  <pre><code>// const AWS = require(&quot;aws-sdk&quot;);
  // var crypto = require(&quot;crypto-js&quot;);
  var CryptoJS = require(&quot;crypto-js&quot;);
  var Crypto = require(&quot;crypto&quot;);
  
  const { CognitoIdentityServiceProvider } = require(&quot;aws-sdk&quot;);
  
  const hashSecret = (clientSecret, username, clientId) =&gt;
    Crypto.createHmac(&quot;SHA256&quot;, clientSecret)
      .update(username + clientId)
      .digest(&quot;base64&quot;);
  
  async function isUserValid() {
    const USER_POOL_ID = &quot;poolid&quot;;
    const CLIENT_ID = &quot;clidntID&quot;;
    const CLIENT_SECRET = &quot;secreteCode&quot;;
  
    const Password = &quot;userName&quot;;
    const Username = &quot;password&quot;;
  
    const cognito = new CognitoIdentityServiceProvider({
      region: &quot;ap-southeast-2&quot;,
    });
  
    try {
      const payload = {
        UserPoolId: USER_POOL_ID,
        AuthFlow: &quot;ADMIN_NO_SRP_AUTH&quot;,
        ClientId: CLIENT_ID,
        AuthParameters: {
          USERNAME: &quot;username&quot;,
          PASSWORD: &quot;password&quot;,
          SECRET_HASH: hashSecret(CLIENT_SECRET, Username, CLIENT_ID),
        },
      };
  
      const response = await cognito.adminInitiateAuth(payload).promise();
      // // console.log(&quot;respone :&quot;, response)
      // console.log(&quot;before response node js lambda  ::: &quot;)
      return response;
    } catch (e) {
      console.log(&quot;error : &quot;, e.message);
    }
  }
  
  async function test() {
    return &quot;test &quot;;
  }
  
  exports.handler = async (event) =&gt; {
    // TODO implement
  
    console.log(&quot;event : &quot;, event);
  '
  
    const response = {
      statusCode: 200,
      headers: {
                      &quot;Content-Type&quot; : &quot;application/json&quot;,
                      &quot;Access-Control-Allow-Origin&quot; : &quot;*&quot;,
                      &quot;X-Content-Type-Option&quot; : &quot;nosniff&quot;,
                      &quot;Content-Security-Policy&quot; :  &quot;default-src self&quot;,
                      &quot;X-frame-options&quot; : &quot;DENY&quot;,
                      &quot;Cache-Control&quot; : &quot;max-age=86400&quot;,
                      &quot;X-XSS-protection&quot; : 0,
                      &quot;X-rate-limit&quot;: 600,
                      &quot;Strict-Transport-Security&quot;: &quot;max-age=31536000; includeSubDomains&quot;,
  
                  },
      // body: await test() // (this response is working fine
      body: await isUserValid(),
    };
    return response;
  };
  </code></pre>
  <p>Errors when tested from API gateway with proxy setting on :
  {
  &quot;message&quot;: &quot;Internal server error&quot;
  }
  Response Headers
  {&quot;x-amzn-ErrorType&quot;:&quot;InternalServerErrorException&quot;}</p>
  <p>I tried multiple options but nothing is working for me.</p>