Skip to content

Commit 7e964c0

Browse files
committed
chore: aws-sdk workaround
1 parent 6d70302 commit 7e964c0

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

packages/testing/src/resources/TestNodejsFunction.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ class TestNodejsFunction extends NodejsFunction {
2828
extraProps: ExtraTestProps
2929
) {
3030
const isESM = extraProps.outputFormat === 'ESM';
31-
const bundling: BundlingOptions = {
31+
const { bundling, ...restProps } = props;
32+
33+
const customBundling: BundlingOptions = {
34+
...bundling,
3235
minify: true,
3336
mainFields: isESM ? ['module', 'main'] : ['main', 'module'],
3437
sourceMap: true,
@@ -42,15 +45,15 @@ class TestNodejsFunction extends NodejsFunction {
4245
timeout: Duration.seconds(30),
4346
memorySize: 256,
4447
tracing: Tracing.ACTIVE,
45-
...props,
48+
...restProps,
4649
functionName: concatenateResourceName({
4750
testName: stack.testName,
4851
resourceName: extraProps.nameSuffix,
4952
}),
5053
runtime: TEST_RUNTIMES[getRuntimeKey()],
5154
architecture: TEST_ARCHITECTURES[getArchitectureKey()],
5255
logRetention: RetentionDays.ONE_DAY,
53-
bundling,
56+
bundling: customBundling,
5457
});
5558

5659
new CfnOutput(this, extraProps.nameSuffix, {

packages/tracer/tests/helpers/resources.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import type { TestStack } from '@aws-lambda-powertools/testing-utils';
1+
import {
2+
TEST_RUNTIMES,
3+
getRuntimeKey,
4+
type TestStack,
5+
} from '@aws-lambda-powertools/testing-utils';
26
import type {
37
ExtraTestProps,
48
TestNodejsFunctionProps,
@@ -27,6 +31,17 @@ class TracerTestNodejsFunction extends TestNodejsFunction {
2731
),
2832
...props.environment,
2933
},
34+
bundling: {
35+
/**
36+
* For Node.js 16.x, we need to set `externalModules` to an empty array
37+
* so that the `aws-sdk` is bundled with the function.
38+
*
39+
* @see https://github.com/aws/aws-sdk-js-v3/issues/3230#issuecomment-1561973247
40+
*/
41+
...(TEST_RUNTIMES[getRuntimeKey()] === TEST_RUNTIMES.nodejs16x && {
42+
externalModules: [],
43+
}),
44+
},
3045
},
3146
extraProps
3247
);

0 commit comments

Comments
 (0)