From d1211aa033c584a53eb012c10835a1a9bf5c9329 Mon Sep 17 00:00:00 2001 From: joaosusaki Date: Mon, 28 Jul 2025 17:18:51 -0300 Subject: [PATCH 1/2] refactor(event-handler): replace EnvironmentVariablesService class with helper functions in Event Handler --- .../event-handler/src/appsync-events/Router.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/event-handler/src/appsync-events/Router.ts b/packages/event-handler/src/appsync-events/Router.ts index 8aa0a10cd6..c30b294a44 100644 --- a/packages/event-handler/src/appsync-events/Router.ts +++ b/packages/event-handler/src/appsync-events/Router.ts @@ -1,4 +1,3 @@ -import { EnvironmentVariablesService } from '@aws-lambda-powertools/commons'; import type { GenericLogger } from '@aws-lambda-powertools/commons/types'; import { isRecord } from '@aws-lambda-powertools/commons/typeutils'; import type { @@ -8,6 +7,7 @@ import type { RouterOptions, } from '../types/appsync-events.js'; import { RouteHandlerRegistry } from './RouteHandlerRegistry.js'; +import { getStringFromEnv, isDevMode } from '@aws-lambda-powertools/commons/utils/env'; /** * Class for registering routes for the `onPublish` and `onSubscribe` events in AWS AppSync Events APIs. @@ -31,14 +31,12 @@ class Router { * Whether the router is running in development mode. */ protected readonly isDev: boolean = false; - /** - * The environment variables service instance. - */ - protected readonly envService: EnvironmentVariablesService; - + public constructor(options?: RouterOptions) { - this.envService = new EnvironmentVariablesService(); - const alcLogLevel = this.envService.get('AWS_LAMBDA_LOG_LEVEL'); + const alcLogLevel = getStringFromEnv({ + key: 'AWS_LAMBDA_LOG_LEVEL', + defaultValue: '', + }); this.logger = options?.logger ?? { debug: alcLogLevel === 'DEBUG' ? console.debug : () => undefined, error: console.error, @@ -52,7 +50,7 @@ class Router { logger: this.logger, eventType: 'onSubscribe', }); - this.isDev = this.envService.isDevMode(); + this.isDev = isDevMode(); } /** From 930ef80e9ee6b65fda4a6c8259411a0ac5503ef7 Mon Sep 17 00:00:00 2001 From: joaosusaki Date: Mon, 28 Jul 2025 17:25:55 -0300 Subject: [PATCH 2/2] refactor(event-handler): Moved the import to top of the file --- packages/event-handler/src/appsync-events/Router.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/event-handler/src/appsync-events/Router.ts b/packages/event-handler/src/appsync-events/Router.ts index c30b294a44..38e189d65d 100644 --- a/packages/event-handler/src/appsync-events/Router.ts +++ b/packages/event-handler/src/appsync-events/Router.ts @@ -1,5 +1,6 @@ import type { GenericLogger } from '@aws-lambda-powertools/commons/types'; import { isRecord } from '@aws-lambda-powertools/commons/typeutils'; +import { getStringFromEnv, isDevMode } from '@aws-lambda-powertools/commons/utils/env'; import type { OnPublishHandler, OnSubscribeHandler, @@ -7,7 +8,6 @@ import type { RouterOptions, } from '../types/appsync-events.js'; import { RouteHandlerRegistry } from './RouteHandlerRegistry.js'; -import { getStringFromEnv, isDevMode } from '@aws-lambda-powertools/commons/utils/env'; /** * Class for registering routes for the `onPublish` and `onSubscribe` events in AWS AppSync Events APIs.