Created
September 7, 2023 10:21
-
-
Save zxkane/dcd36bc9886809ddeb9a427500bb8b7c to your computer and use it in GitHub Desktop.
use custom logger for AWS JS SDK v3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { DescribeParametersCommand, SSMClient } from "@aws-sdk/client-ssm"; | |
import { UserAgent } from '@aws-sdk/types'; | |
import * as log4js from "log4js"; | |
log4js.configure({ | |
appenders: { out: { type: "stdout" } }, | |
categories: { default: { appenders: ["out"], level: "debug" } }, | |
}); | |
const logger = log4js.getLogger(); | |
const userAgent: UserAgent = [['SOLUTION/SOL1234', 'v1.1.0']]; | |
const logRequestMiddleware = (next: any, _context: any) => async (args: any) => { | |
console.log('Request:', args.request); | |
return next(args); | |
}; | |
async function main() { | |
const ssmClient = new SSMClient({ | |
logger: logger, | |
customUserAgent: userAgent, | |
}); | |
ssmClient.middlewareStack.add(logRequestMiddleware, { step: 'finalizeRequest' }); | |
const parameters = await ssmClient.send(new DescribeParametersCommand({})); | |
console.log(parameters); | |
} | |
main().then(() => { | |
console.log('Done'); | |
}).catch(err => { | |
console.error(err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment