Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent duplicated cdk-defined resource ids #7931

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

rafael747
Copy link

Limiting aws:cdk:path metadata partitions length in order to prevent duplicated resource ids. Logical id will be used if it is not possible to ensure that the resource id extracted from aws:cdk:path is unique.

Which issue(s) does this change fix?

#4064
#4034
aws/aws-cdk#21134

Why is this change necessary?

SAM CLI extracts the resource id from aws:cdk:path metadata value when it is present.
This value is always unique when generated by CDK. However, only the second last partition is used, which might not be unique cross all resources in the stack.

  • Stack/aaa/Fn/Resource -> SamResouceId: Fn
  • Stack/bbb/Fn/Resource -> SamResouceId: Fn
  • Stack/ccc/Fn/Resource -> SamResouceId: Fn

How does it address the issue?

By limiting the usage of aws:cdk:path metadata when the number of partitions is bigger than 3.
In these situations, it is not possible to ensure that the second last partition will be unique, and the logical id should be used instead.

What side effects does this change have?

Mandatory Checklist

PRs will only be reviewed after checklist is complete

  • Add input/output type hints to new functions/methods
  • Write design document if needed (Do I need to write a design document?)
  • Write/update unit tests
  • Write/update integration tests
  • Write/update functional tests if needed
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@rafael747 rafael747 requested a review from a team as a code owner March 11, 2025 10:09
@github-actions github-actions bot added pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Mar 11, 2025
Limiting aws:cdk:path metadata partitions length in order to prevent
duplicated resource ids. Logical id will be used if it is not possible
to ensure that the resource id extracted from aws:cdk:path is unique.
@rafael747 rafael747 force-pushed the limit-cdk-path-partitions-length branch from 33d8b1e to bd16106 Compare March 19, 2025 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant