aws / aws/aws-cdk

CustomResourceConfig: addLogRetentionLifetime doesn't work with 2 AwsCustomResources

Open
#34,470 1 comment 0 reactions 0 assignees View on GitHub
@aws-cdk/custom-resources bug p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
1d 19h
Merged PRs (30d)
74

Description

### Describe the bug

CustomResourceConfig.addLogRetentionLifetime() fails at synth-time if I have 2 AwsCustomResources in the stack with:
```
There is already a Construct with name 'logGroup' in CfnFunction [Resource]
```

Works, if there's only 1 AwsCustomResource.

### Regression Issue

- [ ] Select this option if this issue appears to be a regression.

### Last Known Working CDK Library Version

_No response_

### Expected Behavior

No exception

### Current Behavior

```
Exception in thread "main" java.lang.RuntimeException: Error: There is already a Construct with name 'logGroup' in CfnFunction [Resource]
@jsii/kernel.RuntimeError: Error: There is already a Construct with name 'logGroup' in CfnFunction [Resource]
at Kernel._Kernel_ensureSync (/private/var/folders/2f/7cf6g_yj5x10vq_3zclbb72h0000gn/T/jsii-java-runtime17928144539978102170/lib/program.js:927:23)
at Kernel.invoke (/private/var/folders/2f/7cf6g_yj5x10vq_3zclbb72h0000gn/T/jsii-java-runtime17928144539978102170/lib/program.js:294:102)
at KernelHost.processRequest (/private/var/folders/2f/7cf6g_yj5x10vq_3zclbb72h0000gn/T/jsii-java-runtime17928144539978102170/lib/program.js:15467:36)
at KernelHost.run (/private/var/folders/2f/7cf6g_yj5x10vq_3zclbb72h0000gn/T/jsii-java-runtime17928144539978102170/lib/program.js:15427:22)
at Immediate._onImmediate (/private/var/folders/2f/7cf6g_yj5x10vq_3zclbb72h0000gn/T/jsii-java-runtime17928144539978102170/lib/program.js:15428:46)
at process.processImmediate (node:internal/timers:505:21)
at software.amazon.jsii.JsiiRuntime.processErrorResponse(JsiiRuntime.java:147)
at software.amazon.jsii.JsiiRuntime.requestResponse(JsiiRuntime.java:116)
at software.amazon.jsii.JsiiClient.callMethod(JsiiClient.java:184)
at software.amazon.jsii.Kernel.call(Kernel.java:52)
at software.amazon.awscdk.Stage.synth(Stage.java:108)
at com.cartelsol.spike.aws.customresource.infra.CustomResourceMain.main(CustomResourceMain.kt:38)
```

### Reproduction Steps

```
object CustomResourceMain {

@JvmStatic
fun main(vararg args: String) {
val app = App()

val stack = Stack.Builder.create(app, "MyStack")
.stackName("TestStack")
.env(Environment.builder().account("ACCOUNT_ID").region("eu-central-1").build())
.build()

AwsCustomResource.Builder.create(stack, "AwsCustomResource1")
.onCreate(AwsSdkCall.builder().service("Iot").action("describeEndpoint").physicalResourceId(PhysicalResourceId.of("ID1")).build())
.policy(AwsCustomResourcePolicy.fromSdkCalls(SdkCallsPolicyOptions.builder().resources(AwsCustomResourcePolicy.ANY_RESOURCE).build()))
.build()

AwsCustomResource.Builder.create(stack, "AwsCustomResource2")
.onCreate(AwsSdkCall.builder().service("Iot").action("describeEndpoint").physicalResourceId(PhysicalResourceId.of("ID2")).build())
.policy(AwsCustomResourcePolicy.fromSdkCalls(SdkCallsPolicyOptions.builder().resources(AwsCustomResourcePolicy.ANY_RESOURCE).build()))
.build()

CustomResourceConfig.of(app).addLogRetentionLifetime(RetentionDays.TEN_YEARS)

app.synth()
}
}
```

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### AWS CDK Library version (aws-cdk-lib)

2.195.0

### AWS CDK CLI version

2.1014.0

### Node.js Version

22.15.1

### OS

MacOS

### Language

Java

### Language Version

21

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by running the Kotlin reproduction with two AwsCustomResources and CustomResourceConfig.of(app).addLogRetentionLifetime(), then inspect the implementation of CustomResourceConfig and AwsCustomResource around app.synth(). Done means synthesis succeeds with both resources and a regression test confirms that no duplicate 'logGroup' construct error occurs.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, java, typescript
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.