Skip to content

Commit 27d1f24

Browse files
committed
fix: align lambda log group and propagate correlation ids on errors
1 parent 18d6cb5 commit 27d1f24

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

lib/cdk-app-stack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class CdkAppStack extends cdk.Stack {
113113
});
114114

115115
const lambdaAppLogs = new logs.LogGroup(this, 'LambdaApplicationLogs', {
116-
logGroupName: `/aws/lambda/${lambda_backend.functionName}-application`,
116+
logGroupName: `/aws/lambda/${lambda_backend.functionName}`,
117117
encryptionKey,
118118
retention: logs.RetentionDays.ONE_MONTH,
119119
removalPolicy: RemovalPolicy.RETAIN,

lib/function.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ export const handler = async (
4242
event: APIGatewayEvent,
4343
context: Context
4444
): Promise<APIGatewayProxyResult> => {
45-
try {
46-
const correlationId =
47-
event.headers?.['x-correlation-id'] ||
48-
event.headers?.['X-Correlation-Id'] ||
49-
context.awsRequestId;
45+
const correlationId =
46+
event.headers?.['x-correlation-id'] ||
47+
event.headers?.['X-Correlation-Id'] ||
48+
context.awsRequestId;
5049

50+
try {
5151
log('INFO', 'request-received', {
5252
awsRequestId: context.awsRequestId,
5353
correlationId,
@@ -81,6 +81,7 @@ export const handler = async (
8181
headers: {
8282
'Content-Type': 'application/json',
8383
'Access-Control-Allow-Origin': '*',
84+
'x-correlation-id': correlationId,
8485
},
8586
body: JSON.stringify({ error: 'Internal Server Error' }),
8687
};

0 commit comments

Comments
 (0)