Skip to content

Commit 58120e3

Browse files
am29ddreamorosi
andauthored
chore(layers): add Idempotency, Batch, and Parameters to layer (#1712)
* add parameters, batch, idempotency to layer * chore: shave layer size --------- Co-authored-by: Andrea Amorosi <[email protected]>
1 parent ccc0398 commit 58120e3

File tree

4 files changed

+89
-7
lines changed

4 files changed

+89
-7
lines changed

Diff for: layers/src/canary-stack.ts

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ export class CanaryStack extends Stack {
5151
'@aws-lambda-powertools/metrics',
5252
'@aws-lambda-powertools/tracer',
5353
'@aws-lambda-powertools/commons',
54+
'@aws-lambda-powertools/parameters',
55+
'@aws-lambda-powertools/idempotency',
56+
'@aws-lambda-powertools/batch',
5457
],
5558
},
5659
environment: {

Diff for: layers/src/layer-publisher-stack.ts

+45-7
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,62 @@ export class LayerPublisherStack extends Stack {
6060

6161
// This is the list of packages that we need include in the Lambda Layer
6262
// the name is the same as the npm workspace name
63-
const utilities = ['commons', 'logger', 'metrics', 'tracer'];
63+
const utilities = [
64+
'commons',
65+
'logger',
66+
'metrics',
67+
'tracer',
68+
'parameters',
69+
'idempotency',
70+
'batch',
71+
];
6472

6573
// These files are relative to the tmp folder
6674
const filesToRemove = [
6775
'node_modules/@types',
6876
'package.json',
6977
'package-lock.json',
70-
'node_modules/**/README.md',
71-
'node_modules/.bin/semver',
78+
'node_modules/**/*.md',
79+
'node_modules/.bin',
80+
'node_modules/**/*.html',
81+
'node_modules/**/.travis.yml',
82+
'node_modules/**/.eslintrc',
83+
'node_modules/**/.npmignore',
84+
'node_modules/semver/bin',
85+
'node_modules/emitter-listener/test',
86+
'node_modules/fast-xml-parser/cli',
7287
'node_modules/async-hook-jl/test',
88+
'node_modules/stack-chain/test',
7389
'node_modules/shimmer/test',
7490
'node_modules/jmespath/artifacts',
75-
// We remove the type definitions since they can't be used in the Lambda Layer
76-
'node_modules/@aws-lambda-powertools/*/lib/*.d.ts',
77-
'node_modules/@aws-lambda-powertools/*/lib/*.d.ts.map',
91+
'node_modules/jmespath/bower.json',
92+
'node_modules/obliterator/*.d.ts',
93+
'node_modules/strnum/.vscode',
94+
'node_modules/strnum/*.test.js',
95+
'node_modules/uuid/bin',
96+
'node_modules/uuid/esm-browser',
97+
'node_modules/uuid/esm-node',
98+
'node_modules/uuid/umd',
99+
'node_modules/mnemonist/*.d.ts',
100+
// We remove the type definitions and ES builds since they are not used in the Lambda Layer
101+
'node_modules/@aws-lambda-powertools/*/lib/**/*.d.ts',
102+
'node_modules/@aws-lambda-powertools/*/lib/**/*.d.ts.map',
103+
'node_modules/@aws-sdk/*/dist-types',
104+
'node_modules/@aws-sdk/*/dist-es',
105+
'node_modules/@smithy/*/dist-types',
106+
'node_modules/@smithy/*/dist-es',
107+
'node_modules/@smithy/**/README.md ',
108+
'node_modules/@aws-sdk/**/README.md ',
78109
];
79110
const buildCommands: string[] = [];
80-
const modulesToInstall: string[] = [];
111+
// We need these modules because they are not included in the nodejs14x and nodejs16x runtimes
112+
const modulesToInstall: string[] = [
113+
'@aws-sdk/client-dynamodb',
114+
'@aws-sdk/util-dynamodb',
115+
'@aws-sdk/client-ssm',
116+
'@aws-sdk/client-secrets-manager',
117+
'@aws-sdk/client-appconfigdata',
118+
];
81119

82120
if (buildFromLocal) {
83121
for (const util of utilities) {

Diff for: layers/tests/e2e/layerPublisher.class.test.functionCode.ts

+38
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,51 @@ import { readFile } from 'node:fs/promises';
33
import { Logger } from '@aws-lambda-powertools/logger';
44
import { Metrics } from '@aws-lambda-powertools/metrics';
55
import { Tracer } from '@aws-lambda-powertools/tracer';
6+
import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb';
7+
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
8+
import { BatchProcessor, EventType } from '@aws-lambda-powertools/batch';
9+
import { SSMProvider } from '@aws-lambda-powertools/parameters/ssm';
10+
import { SecretsProvider } from '@aws-lambda-powertools/parameters/secrets';
11+
import { AppConfigProvider } from '@aws-lambda-powertools/parameters/appconfig';
12+
import { DynamoDBProvider } from '@aws-lambda-powertools/parameters/dynamodb';
13+
import { SSMClient } from '@aws-sdk/client-ssm';
14+
import { SecretsManagerClient } from '@aws-sdk/client-secrets-manager';
15+
import { AppConfigDataClient } from '@aws-sdk/client-appconfigdata';
616

717
const logger = new Logger({
818
logLevel: 'DEBUG',
919
});
1020
const metrics = new Metrics();
1121
const tracer = new Tracer();
1222

23+
// Instantiating these clients and the respective providers/persistence layers
24+
// will ensure that Idempotency & Parameters are working with
25+
// the AWS SDK v3 client, both coming from the Lambda Layer and the
26+
// bundle
27+
const ddbClient = new DynamoDBClient({});
28+
29+
const ssmClient = new SSMClient({});
30+
31+
const secretsClient = new SecretsManagerClient({});
32+
33+
const appconfigClient = new AppConfigDataClient({});
34+
35+
new DynamoDBPersistenceLayer({
36+
tableName: 'my-idempotency-table',
37+
awsSdkV3Client: ddbClient,
38+
});
39+
40+
new SSMProvider({ awsSdkV3Client: ssmClient });
41+
42+
new SecretsProvider({ awsSdkV3Client: secretsClient });
43+
44+
new AppConfigProvider({ environment: 'foo', awsSdkV3Client: appconfigClient });
45+
46+
new DynamoDBProvider({ tableName: 'foo', awsSdkV3Client: ddbClient });
47+
48+
// Instantiating the BatchProcessor will confirm that the utility can be used
49+
new BatchProcessor(EventType.SQS);
50+
1351
const layerPath = process.env.LAYERS_PATH || '/opt/nodejs/node_modules';
1452
const expectedVersion = process.env.POWERTOOLS_PACKAGE_VERSION || '0.0.0';
1553

Diff for: layers/tests/e2e/layerPublisher.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ describe(`Layers E2E tests, publisher stack`, () => {
9797
'@aws-lambda-powertools/logger',
9898
'@aws-lambda-powertools/metrics',
9999
'@aws-lambda-powertools/tracer',
100+
'@aws-lambda-powertools/parameter',
101+
'@aws-lambda-powertools/idempotency',
102+
'@aws-lambda-powertools/batch',
100103
],
101104
},
102105
layers: [layerVersion],

0 commit comments

Comments
 (0)