# Malformed Lambda proxy response from API Gateway Invocation

**URL:** <https://forum.serverless.com/t/malformed-lambda-proxy-response-from-api-gateway-invocation/1111>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [January 12, 2017, 9:15pm UTC](https://forum.serverless.com/t/malformed-lambda-proxy-response-from-api-gateway-invocation/1111 "2017-01-12T21:15:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kexic](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/kexic/32/406_2.png) [@kexic](https://forum.serverless.com/u/kexic)\
**Post date:** [January 12, 2017, 9:15pm UTC](https://forum.serverless.com/t/malformed-lambda-proxy-response-from-api-gateway-invocation/1111/1 "2017-01-12T21:15:40Z")

</div>

I have been roaming the forums trying to find a resolution to a “Malformed Lambda proxy response” (status: 502) error message you get when deploying and running an API Gateway Invokation that uses a Lambda-Proxy.

Excuse the post length for sake of being exact.

- I followed the API Gateway tutorial as described [in the serverless docs](https://serverless.com/framework/docs/providers/aws/events/apigateway/).

- I ran into a currently open issue with serverless where lambda triggers do not display in the [AWS Console](https://github.com/serverless/serverless/issues/1816), so I added the API Gateway part from API Gateway itself.

- Now, my Lambda function works as expected, but the response from API Gateway is that it is malformed (see code snippet below)

- I then created a Response Model that would shape the response

- I then reviewed my .yml file and it declared the function as follows

- And this seemed all fine, so I looked specifically at the IAM Role to see if I had the correct permissions where I had added explicit invoke access to the resource as follows:

- Which seemed to clear up all permission messages, but I still can’t get past that 502 status of a Malformed Lambda proxy response.

Any ideas what I’ve missed and could I have done all of this via Serverless alone. I am new to Serverless so if I could create the response template, add the IAM permissions, and configure API Gateway to cache the response to 15 minute intervals (on my todo list) ALL within serverless, please help because I’m stumped.

---

<div class="post-metadata">

**Author:** ![kexic](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/kexic/32/406_2.png) [@kexic](https://forum.serverless.com/u/kexic)\
**Post date:** [January 19, 2017, 6:23pm UTC](https://forum.serverless.com/t/malformed-lambda-proxy-response-from-api-gateway-invocation/1111/2 "2017-01-19T18:23:44Z")

</div>

I got it to work, but I’m not sure what it was particularly so I’m outlining the top probabilities for you:

I added the following to my serverless.yml file:

```
iamRoleStatements:
- Effect: Allow
  Action:
    - execute-api:Invoke
  Resource: "arn:aws:execute-api:us-east-1:*:*"

```

I changed the return execution in my handler.js to invoke the context.suceed method

```
context.succeed(result);

```

The issue was that API Gateway didn’t like what Lambda was giving it, which is odd because I began the project serverless-first so perhaps a step is missing in the documentation OR some specific documentation needs to be added to address this approach.

---

<div class="post-metadata">

**Author:** ![buggy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/buggy/32/177_2.png) [@buggy](https://forum.serverless.com/u/buggy)\
**Post date:** [January 20, 2017, 1:41am UTC](https://forum.serverless.com/t/malformed-lambda-proxy-response-from-api-gateway-invocation/1111/3 "2017-01-20T01:41:19Z")

</div>

Hey

I’m not sure why you’re using a response model with Lambda Proxy? The whole point of Lambda Proxy Integration is that you return the status code, headers and body that you want the API gateway to send back.

Rich

---

<div class="post-metadata">

**Author:** ![kexic](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/kexic/32/406_2.png) [@kexic](https://forum.serverless.com/u/kexic)\
**Post date:** [January 23, 2017, 1:02am UTC](https://forum.serverless.com/t/malformed-lambda-proxy-response-from-api-gateway-invocation/1111/4 "2017-01-23T01:02:44Z")

</div>

I thought that was a necessity for API Gateway to conform to. The 502 error I had been running into is not at all informative, so I’m not yet certain what can be trimmed to no effect. Also, I was outlining my path of resolution, so the response model isn’t actually active in my current working code.

Thanks for pointing that out as it would indeed be redundant and its final exclusion was not clearly mentioned in my posts.
