From 407ce07be019647faaca575ad01fe50f2d109219 Mon Sep 17 00:00:00 2001 From: Blayne Chard Date: Tue, 16 Feb 2021 13:50:49 +1300 Subject: [PATCH] feat(lambda): log the lambda request id at the end of every request --- packages/lambda/src/__test__/lambda.test.ts | 6 +++--- packages/lambda/src/lambda.ts | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/lambda/src/__test__/lambda.test.ts b/packages/lambda/src/__test__/lambda.test.ts index 4beec3d46..e710970ac 100644 --- a/packages/lambda/src/__test__/lambda.test.ts +++ b/packages/lambda/src/__test__/lambda.test.ts @@ -18,7 +18,7 @@ o.spec('LambdaFunction', () => { const testFunc = LambdaFunction.wrap(asyncThrow, FakeLogger()); const spy = o.spy(); - await testFunc({ httpMethod: 'GET' } as any, null as any, spy); + await testFunc({ httpMethod: 'GET' } as any, {} as any, spy); o(spy.calls.length).equals(1); const err = spy.args[0]; const res = spy.args[1] as ALBResult; @@ -39,7 +39,7 @@ o.spec('LambdaFunction', () => { const testFunc = LambdaFunction.wrap(asyncThrow, FakeLogger()); const spy = o.spy(); - await testFunc({ Records: [{ cf: { request: { method: 'GET', headers: {} } } }] } as any, null as any, spy); + await testFunc({ Records: [{ cf: { request: { method: 'GET', headers: {} } } }] } as any, {} as any, spy); o(spy.calls.length).equals(1); const err = spy.args[0]; const res = spy.args[1] as CloudFrontResultResponse; @@ -68,7 +68,7 @@ o.spec('LambdaFunction', () => { }, fakeLogger); const spy = o.spy(); - await testFunc({ httpMethod: 'GET' } as any, null as any, spy); + await testFunc({ httpMethod: 'GET' } as any, {} as any, spy); o(spy.calls.length).equals(1); o(spy.args[1]).deepEquals(LambdaContext.toAlbResponse(albOk)); diff --git a/packages/lambda/src/lambda.ts b/packages/lambda/src/lambda.ts index bc5d45b52..d2d88ba91 100644 --- a/packages/lambda/src/lambda.ts +++ b/packages/lambda/src/lambda.ts @@ -35,9 +35,8 @@ export class LambdaFunction { // Trace cloudfront requests back to the cloudfront logs const cloudFrontId = ctx.header(HttpHeaderAmazon.CloudfrontId); const traceId = ctx.header(HttpHeaderAmazon.TraceId); - if (cloudFrontId != null || traceId != null) { - ctx.set('aws', { cloudFrontId, traceId }); - } + const lambdaId = context.awsRequestId; + ctx.set('aws', { cloudFrontId, traceId, lambdaId }); ctx.set('package', { hash: process.env.GIT_HASH, version: process.env.GIT_VERSION }); ctx.set('method', ctx.method);