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.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay