diff --git a/layers/src/layer-publisher-stack.ts b/layers/src/layer-publisher-stack.ts index c61fea4882..024dc81b96 100644 --- a/layers/src/layer-publisher-stack.ts +++ b/layers/src/layer-publisher-stack.ts @@ -66,6 +66,7 @@ export class LayerPublisherStack extends Stack { // the name is the same as the npm workspace name const utilities = [ 'commons', + 'event-handler', 'jmespath', 'logger', 'metrics', diff --git a/layers/tests/e2e/layerPublisher.class.test.functionCode.ts b/layers/tests/e2e/layerPublisher.class.test.functionCode.ts index ed6b0f2d8e..8b68e56a75 100644 --- a/layers/tests/e2e/layerPublisher.class.test.functionCode.ts +++ b/layers/tests/e2e/layerPublisher.class.test.functionCode.ts @@ -1,6 +1,7 @@ import { readFile } from 'node:fs/promises'; import { join } from 'node:path'; import { BatchProcessor, EventType } from '@aws-lambda-powertools/batch'; +import { Router } from '@aws-lambda-powertools/event-handler/http'; import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb'; import { Logger } from '@aws-lambda-powertools/logger'; import { Metrics } from '@aws-lambda-powertools/metrics'; @@ -13,6 +14,7 @@ import { AppConfigDataClient } from '@aws-sdk/client-appconfigdata'; import { DynamoDBClient } from '@aws-sdk/client-dynamodb'; import { SecretsManagerClient } from '@aws-sdk/client-secrets-manager'; import { SSMClient } from '@aws-sdk/client-ssm'; +import type { Context } from 'aws-lambda'; const logger = new Logger({ logLevel: 'DEBUG', @@ -45,9 +47,12 @@ new AppConfigProvider({ environment: 'foo', awsSdkV3Client: appconfigClient }); new DynamoDBProvider({ tableName: 'foo', awsSdkV3Client: ddbClient }); -// Instantiating the BatchProcessor will confirm that the utility can be used new BatchProcessor(EventType.SQS); +const app = new Router({ + logger: { error: () => {}, debug: () => {}, info: () => {}, warn: () => {} }, +}); + const layerPath = process.env.LAYERS_PATH || '/opt/nodejs/node_modules'; const expectedVersion = process.env.POWERTOOLS_PACKAGE_VERSION || '0.0.0'; @@ -79,7 +84,7 @@ const getVersionFromModule = async (moduleName: string): Promise => { return moduleVersion; }; -export const handler = async (_event: unknown): Promise => { +export const handler = async (_event: unknown, context: Context) => { // Check that the packages version matches the expected one for (const moduleName of [ 'commons', @@ -90,6 +95,7 @@ export const handler = async (_event: unknown): Promise => { 'idempotency', 'batch', 'parser', + 'event-handler', ]) { const moduleVersion = await getVersionFromModule(moduleName); if (moduleVersion !== expectedVersion) { @@ -116,4 +122,15 @@ export const handler = async (_event: unknown): Promise => { // the presence of a log will indicate that the logger is working // while the content of the log will indicate that the tracer is working logger.debug('subsegment', { subsegment: subsegment.format() }); + + // Since we're passing an invalid event, the event handler will throw + // an InvalidEventError. This will prove that the event-handler layer + // is working as expected without us having to resolve a full event + try { + await app.resolve({}, context); + } catch (error) { + if ((error as Error).name !== 'InvalidEventError') { + throw error; + } + } };