Verbose logging for AWS JS SDK v3

When programming with the AWS SDK, developers sometimes want to debug a specific HTTP request when invoking an SDK API. Due to the poor documentation of AWS JS SDK v3, it takes a lot of work to find a way to print the verbose logging of AWS SDK by asking it to the LLMs.

Below is a practical tip for enabling verbose logging for AWS JS SDK v3.

Solution 1 - specify a custom logger for AWS SDK clients

 1import { DescribeParametersCommand, SSMClient } from "@aws-sdk/client-ssm";
 2import * as log4js from "log4js";
 3
 4log4js.configure({
 5  appenders: { out: { type: "stdout" } },
 6  categories: { default: { appenders: ["out"], level: "debug" } },
 7});
 8
 9const logger = log4js.getLogger();
10
11const ssmClient = new SSMClient({
12  logger: logger,
13});

Solution 2 - use middleware to hook the life cyele of request

 1import { DescribeParametersCommand, SSMClient } from "@aws-sdk/client-ssm";
 2
 3const logRequestMiddleware = (next: any, _context: any) => async (args: any) => {
 4  console.log('Request:', args.request);
 5  return next(args);
 6};
 7
 8const ssmClient = new SSMClient({
 9});
10
11ssmClient.middlewareStack.add(logRequestMiddleware, { step: 'finalizeRequest' });

See complete working example gist below,