Skip to content

Commit

Permalink
feat: add aws_event and aws_context to each log if the configuration …
Browse files Browse the repository at this point in the history
…enable it
Romakita committed Jul 25, 2024
1 parent 39eb15b commit 81c7b5a
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/infra/aws/log-request/ServerlessLogRequest.ts
Original file line number Diff line number Diff line change
@@ -50,7 +50,6 @@ export class ServerlessLogRequest {

if (logEnd) {
if ($ctx.response.statusCode >= 400) {
console.log("===>", $ctx.error)
$ctx.logger.error({
event: "request.end",
status: $ctx.response.statusCode,
@@ -118,7 +117,9 @@ export class ServerlessLogRequest {
headers: request.headers,
body: request.body,
query: request.query,
params: request.params
params: request.params,
aws_event: ctx.event,
aws_context: ctx.context
}
}

4 changes: 4 additions & 0 deletions packages/lambda/src/auth/handler.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,10 @@ import { PlatformServerless } from "@tsed/platform-serverless"
// shared configuration
const config = {
envs: process.env,
logger: {
level: "info" as never,
requestFields: ["reqId", "method", "url", "duration", "route", "aws_event", "aws_context"]
},
auth: {
// Not applicable here because lambda are packaged and deployed on AWS.
// For this reason, we can't use the file system to store data (prefer S3, DynamoDB, etc.)
3 changes: 2 additions & 1 deletion packages/lambda/src/timeslots/handler.ts
Original file line number Diff line number Diff line change
@@ -11,7 +11,8 @@ const config = {
envs: process.env,
lambda: [TimeslotsController],
logger: {
level: "info" as never
level: "info" as never,
requestFields: ["reqId", "method", "url", "duration", "route", "aws_event", "aws_context"]
},
timeslots: {
// Not applicable here because lambda are packaged and deployed on AWS.

0 comments on commit 81c7b5a

Please sign in to comment.