Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions layers/src/layer-publisher-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
21 changes: 19 additions & 2 deletions layers/tests/e2e/layerPublisher.class.test.functionCode.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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',
Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -79,7 +84,7 @@ const getVersionFromModule = async (moduleName: string): Promise<string> => {
return moduleVersion;
};

export const handler = async (_event: unknown): Promise<void> => {
export const handler = async (_event: unknown, context: Context) => {
// Check that the packages version matches the expected one
for (const moduleName of [
'commons',
Expand All @@ -90,6 +95,7 @@ export const handler = async (_event: unknown): Promise<void> => {
'idempotency',
'batch',
'parser',
'event-handler',
]) {
const moduleVersion = await getVersionFromModule(moduleName);
if (moduleVersion !== expectedVersion) {
Expand All @@ -116,4 +122,15 @@ export const handler = async (_event: unknown): Promise<void> => {
// 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;
}
}
};
Loading