diff --git a/layers/src/canary-stack.ts b/layers/src/canary-stack.ts index 7c710cd976..ca3fec76b8 100644 --- a/layers/src/canary-stack.ts +++ b/layers/src/canary-stack.ts @@ -51,6 +51,9 @@ export class CanaryStack extends Stack { '@aws-lambda-powertools/metrics', '@aws-lambda-powertools/tracer', '@aws-lambda-powertools/commons', + '@aws-lambda-powertools/parameters', + '@aws-lambda-powertools/idempotency', + '@aws-lambda-powertools/batch', ], }, environment: { diff --git a/layers/src/layer-publisher-stack.ts b/layers/src/layer-publisher-stack.ts index ea75124e25..6ef6c19fda 100644 --- a/layers/src/layer-publisher-stack.ts +++ b/layers/src/layer-publisher-stack.ts @@ -60,24 +60,62 @@ export class LayerPublisherStack extends Stack { // This is the list of packages that we need include in the Lambda Layer // the name is the same as the npm workspace name - const utilities = ['commons', 'logger', 'metrics', 'tracer']; + const utilities = [ + 'commons', + 'logger', + 'metrics', + 'tracer', + 'parameters', + 'idempotency', + 'batch', + ]; // These files are relative to the tmp folder const filesToRemove = [ 'node_modules/@types', 'package.json', 'package-lock.json', - 'node_modules/**/README.md', - 'node_modules/.bin/semver', + 'node_modules/**/*.md', + 'node_modules/.bin', + 'node_modules/**/*.html', + 'node_modules/**/.travis.yml', + 'node_modules/**/.eslintrc', + 'node_modules/**/.npmignore', + 'node_modules/semver/bin', + 'node_modules/emitter-listener/test', + 'node_modules/fast-xml-parser/cli', 'node_modules/async-hook-jl/test', + 'node_modules/stack-chain/test', 'node_modules/shimmer/test', 'node_modules/jmespath/artifacts', - // We remove the type definitions since they can't be used in the Lambda Layer - 'node_modules/@aws-lambda-powertools/*/lib/*.d.ts', - 'node_modules/@aws-lambda-powertools/*/lib/*.d.ts.map', + 'node_modules/jmespath/bower.json', + 'node_modules/obliterator/*.d.ts', + 'node_modules/strnum/.vscode', + 'node_modules/strnum/*.test.js', + 'node_modules/uuid/bin', + 'node_modules/uuid/esm-browser', + 'node_modules/uuid/esm-node', + 'node_modules/uuid/umd', + 'node_modules/mnemonist/*.d.ts', + // We remove the type definitions and ES builds since they are not used in the Lambda Layer + 'node_modules/@aws-lambda-powertools/*/lib/**/*.d.ts', + 'node_modules/@aws-lambda-powertools/*/lib/**/*.d.ts.map', + 'node_modules/@aws-sdk/*/dist-types', + 'node_modules/@aws-sdk/*/dist-es', + 'node_modules/@smithy/*/dist-types', + 'node_modules/@smithy/*/dist-es', + 'node_modules/@smithy/**/README.md ', + 'node_modules/@aws-sdk/**/README.md ', ]; const buildCommands: string[] = []; - const modulesToInstall: string[] = []; + // We need these modules because they are not included in the nodejs14x and nodejs16x runtimes + const modulesToInstall: string[] = [ + '@aws-sdk/client-dynamodb', + '@aws-sdk/util-dynamodb', + '@aws-sdk/client-ssm', + '@aws-sdk/client-secrets-manager', + '@aws-sdk/client-appconfigdata', + ]; if (buildFromLocal) { for (const util of utilities) { diff --git a/layers/tests/e2e/layerPublisher.class.test.functionCode.ts b/layers/tests/e2e/layerPublisher.class.test.functionCode.ts index fd89f22a44..d63f389d7c 100644 --- a/layers/tests/e2e/layerPublisher.class.test.functionCode.ts +++ b/layers/tests/e2e/layerPublisher.class.test.functionCode.ts @@ -3,6 +3,16 @@ import { readFile } from 'node:fs/promises'; import { Logger } from '@aws-lambda-powertools/logger'; import { Metrics } from '@aws-lambda-powertools/metrics'; import { Tracer } from '@aws-lambda-powertools/tracer'; +import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb'; +import { DynamoDBClient } from '@aws-sdk/client-dynamodb'; +import { BatchProcessor, EventType } from '@aws-lambda-powertools/batch'; +import { SSMProvider } from '@aws-lambda-powertools/parameters/ssm'; +import { SecretsProvider } from '@aws-lambda-powertools/parameters/secrets'; +import { AppConfigProvider } from '@aws-lambda-powertools/parameters/appconfig'; +import { DynamoDBProvider } from '@aws-lambda-powertools/parameters/dynamodb'; +import { SSMClient } from '@aws-sdk/client-ssm'; +import { SecretsManagerClient } from '@aws-sdk/client-secrets-manager'; +import { AppConfigDataClient } from '@aws-sdk/client-appconfigdata'; const logger = new Logger({ logLevel: 'DEBUG', @@ -10,6 +20,34 @@ const logger = new Logger({ const metrics = new Metrics(); const tracer = new Tracer(); +// Instantiating these clients and the respective providers/persistence layers +// will ensure that Idempotency & Parameters are working with +// the AWS SDK v3 client, both coming from the Lambda Layer and the +// bundle +const ddbClient = new DynamoDBClient({}); + +const ssmClient = new SSMClient({}); + +const secretsClient = new SecretsManagerClient({}); + +const appconfigClient = new AppConfigDataClient({}); + +new DynamoDBPersistenceLayer({ + tableName: 'my-idempotency-table', + awsSdkV3Client: ddbClient, +}); + +new SSMProvider({ awsSdkV3Client: ssmClient }); + +new SecretsProvider({ awsSdkV3Client: secretsClient }); + +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 layerPath = process.env.LAYERS_PATH || '/opt/nodejs/node_modules'; const expectedVersion = process.env.POWERTOOLS_PACKAGE_VERSION || '0.0.0'; diff --git a/layers/tests/e2e/layerPublisher.test.ts b/layers/tests/e2e/layerPublisher.test.ts index 52eff56c61..09aebc671d 100644 --- a/layers/tests/e2e/layerPublisher.test.ts +++ b/layers/tests/e2e/layerPublisher.test.ts @@ -97,6 +97,9 @@ describe(`Layers E2E tests, publisher stack`, () => { '@aws-lambda-powertools/logger', '@aws-lambda-powertools/metrics', '@aws-lambda-powertools/tracer', + '@aws-lambda-powertools/parameter', + '@aws-lambda-powertools/idempotency', + '@aws-lambda-powertools/batch', ], }, layers: [layerVersion],