dsi-aws-boilerplate
v4.0.8
Published
A collection of AWS boilerplates
Downloads
90
Maintainers
Keywords
Readme
Deprecated
Please don't use this if you are starting a new project please look at: aws-lambda-logger
KMS Is deprecated we use SSM now
The logger is in aws-lambda-logger
Usage
Create an instance of the logger at the top of your handler method and pass it through to anything that needs logging so that all logs remain connected by their awsRequestId.
Note: When logging typescript errors, it's recommended to wrap the error in the serializeError method so that everything is logged correctly. Errors thrown may be more complex than a simple typescript Error object and have complex properties that the logger won't pick up by default.
...
import { createLogger, Logger, serializeError } from 'dsi-aws-boilerplate';
...
export const handlerMethod = async (event: any, context: any): Promise<any> => {
let logger: Logger;
try {
logger = createLogger(!!(event?.debug || process.env.DEBUG), context.awsRequestId);
...
logger.debug('event', { event: event });
...
} catch (error) {
logger?.error('handler_error', { error: serializeError(error) });
...
}
};