Skip to content

chore(layers): add Idempotency, Batch, and Parameters to layer #1712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 26, 2023
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
3 changes: 3 additions & 0 deletions layers/src/canary-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
52 changes: 45 additions & 7 deletions layers/src/layer-publisher-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
38 changes: 38 additions & 0 deletions layers/tests/e2e/layerPublisher.class.test.functionCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,51 @@ 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',
});
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';

Expand Down
3 changes: 3 additions & 0 deletions layers/tests/e2e/layerPublisher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down