Skip to content

Commit 3259b95

Browse files
committed
chore(maintenance): switch to unmanaged log group for functions
1 parent 7336b2d commit 3259b95

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

packages/testing/src/resources/TestNodejsFunction.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { randomUUID } from 'node:crypto';
22
import { CfnOutput, Duration } from 'aws-cdk-lib';
33
import { Tracing } from 'aws-cdk-lib/aws-lambda';
44
import { NodejsFunction, OutputFormat } from 'aws-cdk-lib/aws-lambda-nodejs';
5-
import { RetentionDays } from 'aws-cdk-lib/aws-logs';
5+
import { RetentionDays, LogGroup } from 'aws-cdk-lib/aws-logs';
66
import type { TestStack } from '../TestStack.js';
77
import { TEST_ARCHITECTURES, TEST_RUNTIMES } from '../constants.js';
88
import {
@@ -25,8 +25,17 @@ class TestNodejsFunction extends NodejsFunction {
2525
) {
2626
const isESM = extraProps.outputFormat === 'ESM';
2727
const { bundling, ...restProps } = props;
28+
const functionName = concatenateResourceName({
29+
testName: stack.testName,
30+
resourceName: extraProps.nameSuffix,
31+
});
32+
const resourceId = randomUUID().substring(0, 5);
2833

29-
super(stack.stack, `fn-${randomUUID().substring(0, 5)}`, {
34+
const logGroup = new LogGroup(this, `log-${resourceId}`, {
35+
logGroupName: `/aws/lambda/${functionName}`,
36+
retention: RetentionDays.ONE_DAY,
37+
});
38+
super(stack.stack, `fn-${resourceId}`, {
3039
timeout: Duration.seconds(30),
3140
memorySize: 512,
3241
tracing: Tracing.ACTIVE,
@@ -41,13 +50,10 @@ class TestNodejsFunction extends NodejsFunction {
4150
: '',
4251
},
4352
...restProps,
44-
functionName: concatenateResourceName({
45-
testName: stack.testName,
46-
resourceName: extraProps.nameSuffix,
47-
}),
53+
functionName,
4854
runtime: TEST_RUNTIMES[getRuntimeKey()],
4955
architecture: TEST_ARCHITECTURES[getArchitectureKey()],
50-
logRetention: RetentionDays.ONE_DAY,
56+
logGroup,
5157
});
5258

5359
new CfnOutput(this, extraProps.nameSuffix, {

0 commit comments

Comments
 (0)