Resolve AWS Lambda Function Failures Faster by Monitoring Invocation Payloads | Datadog

Resolve AWS Lambda function failures faster by monitoring invocation payloads

Author Jordan Obey
Author Alex Cuoci

Published: 10月 8, 2021

In a serverless application, AWS Lambda functions 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

Dive into AWS Lambda function requests and responses

Once you’ve configured payload 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

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 provides end-to-end visibility into requests as they propagate across your services. Datadog can now tag spans 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 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.

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 with Datadog Distributed Tracing to index spans for critical requests. Then, you can turn your span tags into 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.

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

If you aren’t already using Datadog, get started today with a 14-day .