Skip to content

Commit 4a580d4

Browse files
svozzadreamorosi
andauthored
chore(ci): update layer script to include event-handler (#4956)
Co-authored-by: Andrea Amorosi <dreamorosi@gmail.com>
1 parent fe6cf78 commit 4a580d4

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

layers/src/layer-publisher-stack.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export class LayerPublisherStack extends Stack {
6666
// the name is the same as the npm workspace name
6767
const utilities = [
6868
'commons',
69+
'event-handler',
6970
'jmespath',
7071
'logger',
7172
'metrics',

layers/tests/e2e/layerPublisher.class.test.functionCode.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { readFile } from 'node:fs/promises';
22
import { join } from 'node:path';
33
import { BatchProcessor, EventType } from '@aws-lambda-powertools/batch';
4+
import { Router } from '@aws-lambda-powertools/event-handler/http';
45
import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb';
56
import { Logger } from '@aws-lambda-powertools/logger';
67
import { Metrics } from '@aws-lambda-powertools/metrics';
@@ -13,6 +14,7 @@ import { AppConfigDataClient } from '@aws-sdk/client-appconfigdata';
1314
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
1415
import { SecretsManagerClient } from '@aws-sdk/client-secrets-manager';
1516
import { SSMClient } from '@aws-sdk/client-ssm';
17+
import type { Context } from 'aws-lambda';
1618

1719
const logger = new Logger({
1820
logLevel: 'DEBUG',
@@ -45,9 +47,12 @@ new AppConfigProvider({ environment: 'foo', awsSdkV3Client: appconfigClient });
4547

4648
new DynamoDBProvider({ tableName: 'foo', awsSdkV3Client: ddbClient });
4749

48-
// Instantiating the BatchProcessor will confirm that the utility can be used
4950
new BatchProcessor(EventType.SQS);
5051

52+
const app = new Router({
53+
logger: { error: () => {}, debug: () => {}, info: () => {}, warn: () => {} },
54+
});
55+
5156
const layerPath = process.env.LAYERS_PATH || '/opt/nodejs/node_modules';
5257
const 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

Comments
 (0)