# Event.body LAMBDA\_PROXY mapping

**URL:** <https://forum.serverless.com/t/event-body-lambda-proxy-mapping/1176>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [January 26, 2017, 5:54am UTC](https://forum.serverless.com/t/event-body-lambda-proxy-mapping/1176 "2017-01-26T05:54:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hendry](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/hendry/32/343_2.png) [@hendry](https://forum.serverless.com/u/hendry)\
**Post date:** [January 26, 2017, 5:54am UTC](https://forum.serverless.com/t/event-body-lambda-proxy-mapping/1176/1 "2017-01-26T05:54:53Z")

</div>

Hi there,

I gather from [https://serverless.com/framework/docs/providers/aws/events/apigateway/](https://serverless.com/framework/docs/providers/aws/events/apigateway/) I need to do something like a:

```
	if (event.body) {
 		event = JSON.parse(event.body)
 	}

```

In my code?

I am quite familiar with doing something like a `sls invoke -f dosomething -p events/notification.json` locally, so I am little bit bewildered by this kludge needed for the event object when using the “http” event.

Please let me know if I am going crazy.

---

<div class="post-metadata">

**Author:** ![rowanu](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/rowanu/32/75_2.png) [@rowanu](https://forum.serverless.com/u/rowanu)\
**Post date:** [January 26, 2017, 9:04am UTC](https://forum.serverless.com/t/event-body-lambda-proxy-mapping/1176/2 "2017-01-26T09:04:32Z")

</div>

The Lambda Proxy integration is still relatively new, so it’s not without its rough edges.

As the content could be JSON - or it _could not_ - there’s currently no assumption made about the content type. If it’s JSON, treat it like serialised JSON. The service makes no attempt to read the headers and work out the content type for you.

Now that you mention it, that sounds like a good idea for a PR…

---

<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 26, 2017, 11:31am UTC](https://forum.serverless.com/t/event-body-lambda-proxy-mapping/1176/3 "2017-01-26T11:31:47Z")

</div>

Hey @hendry

I’ll assume your building an API that only accepts JSON.

The input is a serialized JSON object so you’re not going crazy. I’ve been using the following:

```javascript
try {
    const json = JSON.parse(event.body);

    // YOUR CODE HERE

} catch (e) {
    console.error(e);
    callback(null, { statusCode: 500, headers: { "Content-Type": "application/json"}, body: JSON.stringify({ message: "Internal Error" }) });
}

```

Any uncaught exceptions, which could include de-serializing the JSON, result in a 500 error.

---

<div class="post-metadata">

**Author:** ![hendry](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/hendry/32/343_2.png) [@hendry](https://forum.serverless.com/u/hendry)\
**Post date:** [January 28, 2017, 3:30am UTC](https://forum.serverless.com/t/event-body-lambda-proxy-mapping/1176/4 "2017-01-28T03:30:53Z")

</div>

> [@buggy](#):
>
> I’ll assume your building an API that only accepts JSON.

Oh but the point I was trying to make is that usually that comes down as the `event` in my other lambda functions, so this inconsistency RE API gateway is a bit annoying.

---

<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 28, 2017, 6:04am UTC](https://forum.serverless.com/t/event-body-lambda-proxy-mapping/1176/5 "2017-01-28T06:04:13Z")

</div>

The `event` is specific to the source. With Lambda proxy your Lambda is processing a generic HTTP request so this approach makes sense. The user could be sending XML, HTTP POST parameters or anything they want in the body. The only way the Lambda proxy integration can deal with every possibility is to pass the entire request to the Lambda and let it deal with it. That’s why you need parse the body first.

If you want to receive a JSON object then you should switch from Lambda proxy to Lambda integration.

The reason I said about only accepting JSON is so that I didn’t need to check the `Content-Type` header first.
