From e65f17be03a1164ab01682b49ae53b844cfcb548 Mon Sep 17 00:00:00 2001 From: Mark Slowey Date: Thu, 12 Feb 2026 15:39:05 +0000 Subject: [PATCH 1/2] console.log the metric to be picked up --- lambdas/authorizer/src/__tests__/index.test.ts | 17 +++++++---------- lambdas/authorizer/src/authorizer.ts | 8 +++----- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/lambdas/authorizer/src/__tests__/index.test.ts b/lambdas/authorizer/src/__tests__/index.test.ts index 4020b55e..cecfbe10 100644 --- a/lambdas/authorizer/src/__tests__/index.test.ts +++ b/lambdas/authorizer/src/__tests__/index.test.ts @@ -56,14 +56,18 @@ describe("Authorizer Lambda Function", () => { }); describe("Certificate expiry check", () => { + let consoleLogSpy: jest.SpyInstance; + beforeEach(() => { jest .useFakeTimers({ doNotFake: ["nextTick"] }) .setSystemTime(new Date("2025-11-03T14:19:00Z")); + consoleLogSpy = jest.spyOn(console, "log").mockImplementation(); }); afterEach(() => { jest.useRealTimers(); + consoleLogSpy.mockRestore(); }); it("Should not log CloudWatch metric when certificate is null", async () => { @@ -73,10 +77,7 @@ describe("Authorizer Lambda Function", () => { handler(mockEvent, mockContext, mockCallback); await new Promise(process.nextTick); - const mockedInfo = mockedDeps.logger.info as jest.Mock; - expect(mockedInfo.mock.calls).not.toContainEqual( - expect.stringContaining("CloudWatchMetrics"), - ); + expect(consoleLogSpy).not.toHaveBeenCalled(); }); it("Should log CloudWatch metric when the certificate expiry threshold is reached", async () => { @@ -88,8 +89,7 @@ describe("Authorizer Lambda Function", () => { handler(mockEvent, mockContext, mockCallback); await new Promise(process.nextTick); - const mockedInfo = mockedDeps.logger.info as jest.Mock; - expect(mockedInfo.mock.calls.map((call) => call[0])).toContain( + expect(consoleLogSpy).toHaveBeenCalledWith( JSON.stringify({ _aws: { Timestamp: 1_762_179_540_000, @@ -123,10 +123,7 @@ describe("Authorizer Lambda Function", () => { handler(mockEvent, mockContext, mockCallback); await new Promise(process.nextTick); - const mockedInfo = mockedDeps.logger.info as jest.Mock; - expect(mockedInfo.mock.calls).not.toContainEqual( - expect.stringContaining("CloudWatchMetrics"), - ); + expect(consoleLogSpy).not.toHaveBeenCalled(); }); }); diff --git a/lambdas/authorizer/src/authorizer.ts b/lambdas/authorizer/src/authorizer.ts index d5a0bd55..87eb65b4 100644 --- a/lambdas/authorizer/src/authorizer.ts +++ b/lambdas/authorizer/src/authorizer.ts @@ -146,10 +146,8 @@ async function checkCertificateExpiry( const expiry = getCertificateExpiryInDays(certificate); if (expiry <= deps.env.CLIENT_CERTIFICATE_EXPIRATION_ALERT_DAYS) { - deps.logger.info( - JSON.stringify( - buildCloudWatchMetric(deps.env.CLOUDWATCH_NAMESPACE, certificate), - ), - ); + let metric = buildCloudWatchMetric(deps.env.CLOUDWATCH_NAMESPACE, certificate); + deps.logger.warn(metric, `APIM Certificated expiry in ${expiry} days`); + console.log(JSON.stringify(metric)); } } From c1425c5193d50008cd08a9523b91b1c1167bfa42 Mon Sep 17 00:00:00 2001 From: Mark Slowey Date: Thu, 12 Feb 2026 16:13:28 +0000 Subject: [PATCH 2/2] lint --- lambdas/authorizer/src/authorizer.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lambdas/authorizer/src/authorizer.ts b/lambdas/authorizer/src/authorizer.ts index 87eb65b4..37b2224d 100644 --- a/lambdas/authorizer/src/authorizer.ts +++ b/lambdas/authorizer/src/authorizer.ts @@ -146,7 +146,10 @@ async function checkCertificateExpiry( const expiry = getCertificateExpiryInDays(certificate); if (expiry <= deps.env.CLIENT_CERTIFICATE_EXPIRATION_ALERT_DAYS) { - let metric = buildCloudWatchMetric(deps.env.CLOUDWATCH_NAMESPACE, certificate); + const metric = buildCloudWatchMetric( + deps.env.CLOUDWATCH_NAMESPACE, + certificate, + ); deps.logger.warn(metric, `APIM Certificated expiry in ${expiry} days`); console.log(JSON.stringify(metric)); }