DEV Community

Mark Tse
Mark Tse

Posted on • Originally published at blog.neverendingqs.com on

2 3

Getting the Request ID of a Lambda Invocation when Using Promises With the AWS SDK

Every invocation of an AWS Lambda function is associated with a request ID. Searching the CloudWatch logs with the request ID is the quickest way to find the logs of a given invocation.

To get the request ID when using the JavaScript AWS SDK, you can access the $response property of the response:

const AWS = require('aws-sdk');
const lambda = new AWS.Lambda();

const response = await lambda.invoke({
  ...
}).promise();

const requestId = response.$response.requestId;

The entire response object from the HTTP request is available to you via the $response object. Also, the $response object is available across almost all API calls, not just lambda.invoke().promise().

If you ever want to track down the results of a single invocation among many, consider logging the response ID.

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

DEV shines when you're signed in, unlocking a customized experience with features like dark mode!

Okay