11import { readFile } from 'node:fs/promises' ;
22import { join } from 'node:path' ;
33import { BatchProcessor , EventType } from '@aws-lambda-powertools/batch' ;
4+ import { Router } from '@aws-lambda-powertools/event-handler/http' ;
45import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb' ;
56import { Logger } from '@aws-lambda-powertools/logger' ;
67import { Metrics } from '@aws-lambda-powertools/metrics' ;
@@ -13,6 +14,7 @@ import { AppConfigDataClient } from '@aws-sdk/client-appconfigdata';
1314import { DynamoDBClient } from '@aws-sdk/client-dynamodb' ;
1415import { SecretsManagerClient } from '@aws-sdk/client-secrets-manager' ;
1516import { SSMClient } from '@aws-sdk/client-ssm' ;
17+ import type { Context } from 'aws-lambda' ;
1618
1719const logger = new Logger ( {
1820 logLevel : 'DEBUG' ,
@@ -45,9 +47,12 @@ new AppConfigProvider({ environment: 'foo', awsSdkV3Client: appconfigClient });
4547
4648new DynamoDBProvider ( { tableName : 'foo' , awsSdkV3Client : ddbClient } ) ;
4749
48- // Instantiating the BatchProcessor will confirm that the utility can be used
4950new BatchProcessor ( EventType . SQS ) ;
5051
52+ const app = new Router ( {
53+ logger : { error : ( ) => { } , debug : ( ) => { } , info : ( ) => { } , warn : ( ) => { } } ,
54+ } ) ;
55+
5156const layerPath = process . env . LAYERS_PATH || '/opt/nodejs/node_modules' ;
5257const expectedVersion = process . env . POWERTOOLS_PACKAGE_VERSION || '0.0.0' ;
5358
@@ -79,7 +84,7 @@ const getVersionFromModule = async (moduleName: string): Promise<string> => {
7984 return moduleVersion ;
8085} ;
8186
82- export const handler = async ( _event : unknown ) : Promise < void > => {
87+ export const handler = async ( _event : unknown , context : Context ) => {
8388 // Check that the packages version matches the expected one
8489 for ( const moduleName of [
8590 'commons' ,
@@ -90,6 +95,7 @@ export const handler = async (_event: unknown): Promise<void> => {
9095 'idempotency' ,
9196 'batch' ,
9297 'parser' ,
98+ 'event-handler' ,
9399 ] ) {
94100 const moduleVersion = await getVersionFromModule ( moduleName ) ;
95101 if ( moduleVersion !== expectedVersion ) {
@@ -116,4 +122,15 @@ export const handler = async (_event: unknown): Promise<void> => {
116122 // the presence of a log will indicate that the logger is working
117123 // while the content of the log will indicate that the tracer is working
118124 logger . debug ( 'subsegment' , { subsegment : subsegment . format ( ) } ) ;
125+
126+ // Since we're passing an invalid event, the event handler will throw
127+ // an InvalidEventError. This will prove that the event-handler layer
128+ // is working as expected without us having to resolve a full event
129+ try {
130+ await app . resolve ( { } , context ) ;
131+ } catch ( error ) {
132+ if ( ( error as Error ) . name !== 'InvalidEventError' ) {
133+ throw error ;
134+ }
135+ }
119136} ;
0 commit comments