# Lamba Proxy not working on 1.26.1

**URL:** <https://forum.serverless.com/t/lamba-proxy-not-working-on-1-26-1/3976>\
**Category:** Serverless Framework\
**Created:** [March 10, 2018, 5:41pm UTC](https://forum.serverless.com/t/lamba-proxy-not-working-on-1-26-1/3976 "2018-03-10T17:41:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![walkerlangley](https://avatars.discourse-cdn.com/v4/letter/w/ad7895/32.png) [@walkerlangley](https://forum.serverless.com/u/walkerlangley)\
**Post date:** [March 10, 2018, 5:41pm UTC](https://forum.serverless.com/t/lamba-proxy-not-working-on-1-26-1/3976/1 "2018-03-10T17:41:33Z")

</div>

Anyone have any issues getting lambda proxy to work? My function works fine when invoked locally and when running serverless-offline, but once I deploy, the function doesn’t return (however the log right before the callback logs out) and there aren’t any errors in Cloudwatch. It just say that the function timed out (at 15 seconds which is plenty long enough).

Any help would be greatly appreciated.

```javascript
  console.log('EXP: ', exp); // This logs in cloudwatch

  return callback(null, {
    statusCode: 200,
    headers: {
      'Set-Cookie': `x-jwt=${token}; expires=${exp}`,
      'Access-Control-Allow-Origin' : "*", // Required for CORS support to work
      'Access-Control-Allow-Credentials' : true // Required for cookies, authorization headers with HTTPS
    }
  });

```

- serverless.yml

```auto
service: wl-login-test

plugins:
  - serverless-webpack
  - serverless-offline

custom:
  webpackIncludeModules: true
  serverless-offline:
    babelOptions:
      presets: ["env"]

provider:
  name: aws
  runtime: nodejs6.10
  stage: dev
  region: us-east-1
  timeout: 15

functions:
  login:
    handler: handler.login
    environment:
      SECRET: secret
      TABLE_NAME: tableName
      AWS_PROFILE: profile
      POSTGRES_USER: user
      POSTGRES_PASSWORD: pgPassword
      POSTGRES_DB: dbName
      POSTGRES_HOST: hostName
    events:
      - http:
          path: login
          method: post
          cors: true

```

---

<div class="post-metadata">

**Author:** ![walkerlangley](https://avatars.discourse-cdn.com/v4/letter/w/ad7895/32.png) [@walkerlangley](https://forum.serverless.com/u/walkerlangley)\
**Post date:** [March 10, 2018, 9:04pm UTC](https://forum.serverless.com/t/lamba-proxy-not-working-on-1-26-1/3976/2 "2018-03-10T21:04:59Z")

</div>

Ok, so after playing around, I realized that if I don’t query my database, the function returns as expected. The following code works as expected

```javascript
const login = async (event, context, callback) => {

  const body = JSON.parse(event.body);
  const email = body.email.toLowerCase();
  const { password } = body

  //const usr = await user.get(email);
  //console.log('USR: ', usr);
  //if (!usr) {
    //callback(null, {
      //statusCode: 401,
      //message: `No user found for email: ${email}`
    //});
  //}

  const response = {
    statusCode: 200,
    body: JSON.stringify({user: 'usr'})
  };
  callback(null, response); // This returns as expected

```

however, if I query a user (the commented out code above) the user is found (ie console.log('USR: ', usr) returns), but the callback never fires and the function times out. I’m thinking that maybe the issue is the db connection isn’t being closed. Thoughts?

```javascript
const login = async (event, context, callback) => {

  const body = JSON.parse(event.body);
  const email = body.email.toLowerCase();
  const { password } = body

  const usr = await user.get(email);
  console.log('USR: ', usr); // This returns find
  if (!usr) {
    callback(null, {
      statusCode: 401,
      message: `No user found for email: ${email}`
    });
  }

  const response = {
    statusCode: 200,
    body: JSON.stringify({user: usr})
  };
  console.log('Response: ', response) // This logs as well
  callback(null, response); // This returns as expected

```

---

<div class="post-metadata">

**Author:** ![walkerlangley](https://avatars.discourse-cdn.com/v4/letter/w/ad7895/32.png) [@walkerlangley](https://forum.serverless.com/u/walkerlangley)\
**Post date:** [March 10, 2018, 10:23pm UTC](https://forum.serverless.com/t/lamba-proxy-not-working-on-1-26-1/3976/3 "2018-03-10T22:23:33Z")

</div>

Turns out using `context.callbackWaitsForEmptyEventLoop = false` saves the day.

---

<div class="post-metadata">

**Author:** ![fredcallagan](https://avatars.discourse-cdn.com/v4/letter/f/f17d59/32.png) [@fredcallagan](https://forum.serverless.com/u/fredcallagan)\
**Post date:** [September 17, 2018, 7:46pm UTC](https://forum.serverless.com/t/lamba-proxy-not-working-on-1-26-1/3976/4 "2018-09-17T19:46:03Z")

</div>

Thanks that saved my day too!
