---
title: "Resolve AWS Lambda function failures faster by monitoring invocation payloads"
description: "Learn how Lambda function request and response payloads can speed up troubleshooting by providing you with deeper insight into function failures"
author: "Jordan Obey, Alex Cuoci"
date: 2021-10-08
tags: ["apm", "serverless monitoring", "serverless"]
blog_type_id: the-monitor
locale: en
---

In a serverless application, [AWS Lambda functions](https://aws.amazon.com/lambda/) are typically invoked by JSON-formatted events from other AWS services—like API Gateway, S3, and DynamoDB—and respond with JSON-formatted payloads. Having visibility into these function request and response payloads can provide context around your function invocations and help you uncover the root causes of Lambda function failures. For example, examining these payloads can help you determine if a function failed due to a misconfigured request or a code issue within the function itself.

To help you quickly identify and troubleshoot Lambda function failures, you can now use Datadog to collect and visualize the JSON request and response payloads of AWS Lambda functions, giving you deeper insight into your serverless applications and helping troubleshoot problems.

![View JSON request and response payloads of lambda functions to facilitate your troubleshooting](https://web-assets.dd-static.net/42588/1776305182-troubleshoot-lambda-function-request-response-payloads-lambda-payload-screenshot05.png)

## Dive into AWS Lambda function requests and responses

Once you've [configured payload](https://docs.datadoghq.com/serverless/distributed_tracing/collect_lambda_payloads.md) ingestion, Datadog will automatically collect function requests and responses for all of your function invocations, providing key information that can help troubleshoot issues. For example, if you're notified that one of your Lambda functions is experiencing failures, you can dive into the relevant request payloads to check for missing parameters, mistyped resource addresses, or other misconfigurations that may be behind the failures.

By identifying misconfigurations in failing requests, you can more easily reproduce issues in your development environment—and then run tests to verify your bug fixes.

![View Lambda function requests to identify any misconfigurations](https://web-assets.dd-static.net/42588/1776305187-troubleshoot-lambda-function-request-response-payloads-lambda-payload-screenshot06.png)

In addition to viewing requests, viewing function responses can also help you better understand issues that may occur. For instance, let's say you have a Lambda function that is triggered by API Gateway and is expected to return specific data to an end user. You can verify that behavior by directly viewing your function's response payloads. This is particularly useful in situations where your functions may be failing silently by returning 200 status codes but not executing their tasks as expected.

Datadog also provides the option to scrub specific parameters from collected payload. This prevents any sensitive data within either request or response JSON objects—like account IDs or addresses—from being collected.

## Quickly surface relevant function traces 

[Tracing your serverless applications](https://www.datadoghq.com/blog/tracing-lambda-datadog-apm.md) provides end-to-end visibility into requests as they propagate across your services. Datadog can now [tag spans](https://docs.datadoghq.com/tracing/visualization.md#span-tags) that represent function invocations with relevant data from your request and response payloads. This helps accelerate troubleshooting by allowing you to use specific payload data to [search and filter](https://docs.datadoghq.com/tracing/trace_search_and_analytics.md) real-time and historical traces of invoked Lambda functions without any additional code changes or configuration.

Let's say you're troubleshooting an e-commerce application. Investigating request payloads, you see that issues are connected to checking out a specific item, as indicated with the `ItemID` parameter. You can then search your traces for `ItemID:12345` to surface other Lambda function requests that include that particular item ID as a payload parameter. This way you can quickly dive into the relevant traces to determine whether an issue is caused by a timeout (indicated by a particularly slow span), a 5xx internal server error, or another unexpected problem.

![You can search traces with specific payload parameters in Datadog APM to surface relevant Lambda requests.](https://web-assets.dd-static.net/42588/1776305192-troubleshoot-lambda-function-request-response-payloads-lambda-payload-screenshot03.png)
*You can search traces with specific payload parameters in Datadog APM to surface relevant Lambda requests.*

You can also set tag-based [retention filters](https://docs.datadoghq.com/tracing/trace_retention_and_ingestion.md#retention-filters) with [Datadog Distributed Tracing](https://docs.datadoghq.com/tracing/trace_explorer.md?tab=listview) to [index spans](https://docs.datadoghq.com/tracing/visualization.md#indexed-span) for critical requests. Then, you can turn your span tags into [facets](https://docs.datadoghq.com/tracing/trace_search_and_analytics/query_syntax.md#facets), enabling you to use historical data to run quick analysis on Lambda function requests. Using our example from above, you can turn `ItemID` into a facet so you can see the latency distribution of all Lambda function requests that include `ItemID:12345`, helping you gauge the scope of the issue.

![Turn payload parameters into facets to filter traces and scope your view to the requests you’re most interest in.](https://web-assets.dd-static.net/42588/1776305196-troubleshoot-lambda-function-request-response-payloads-lambda-payload-screenshot04.png)
*Turn payload parameters into facets to filter traces and scope your view to the requests you’re most interest in.*

## AWS Lambda function payloads right at your fingertips

Datadog helps speed up your AWS Lambda function troubleshooting by providing you with an in-depth look at request and response payloads as well as tagging function invocation traces with payload attributes. Payload ingestion is currently available for the Python and Node.js runtimes. You can enable it by adding the environment variable `DD_CAPTURE_LAMBDA_PAYLOAD` to your Lambda functions and setting it to `true`. To learn more about how to set up and configure Datadog payload configuration please see our documentation [here](https://docs.datadoghq.com/serverless/distributed_tracing/collect_lambda_payloads.md)

If you aren’t already using Datadog, get started today with a 14-day <!-- Sign-up trigger (free trial) omitted -->.