@@ -2,7 +2,7 @@ import { randomUUID } from 'node:crypto';
22import { CfnOutput , Duration } from 'aws-cdk-lib' ;
33import { Tracing } from 'aws-cdk-lib/aws-lambda' ;
44import { NodejsFunction , OutputFormat } from 'aws-cdk-lib/aws-lambda-nodejs' ;
5- import { RetentionDays } from 'aws-cdk-lib/aws-logs' ;
5+ import { LogGroup , RetentionDays } from 'aws-cdk-lib/aws-logs' ;
66import type { TestStack } from '../TestStack.js' ;
77import { TEST_ARCHITECTURES , TEST_RUNTIMES } from '../constants.js' ;
88import {
@@ -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 ( stack . stack , `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