Skip to content

fix(dynamodb): use concrete ARN account/region when resourceName is tokenized - #38485

Open
sanyamk23 wants to merge 2 commits into
aws:mainfrom
sanyamk23:fix/dynamodb-table-v2-partial-arn-validation
Open

fix(dynamodb): use concrete ARN account/region when resourceName is tokenized#38485
sanyamk23 wants to merge 2 commits into
aws:mainfrom
sanyamk23:fix/dynamodb-table-v2-partial-arn-validation

Conversation

@sanyamk23

@sanyamk23 sanyamk23 commented Aug 3, 2026

Copy link
Copy Markdown

Issue # (if applicable)

Closes #38354

Description

The previous broad Token.isUnresolved(tableArn) guard in validateMultiAccountReplica skipped the splitArn extraction whenever any part of the source table ARN was tokenized — even if only the resourceName was a token with concrete account and region parts.

This caused sourceAccount and sourceRegion to fall back to the stack that owns the imported resource (often the same as the replica stack), which falsely triggered the MultiAccountReplicaMustBeDifferentAccount and MultiAccountReplicaMustBeDifferentRegion errors for imported tables whose ARN had a tokenized table name.

Changes

  • packages/aws-cdk-lib/aws-dynamodb/lib/table-v2.ts: Always call splitArn; use the extracted account/region whenever they are concrete (not tokens), falling back to the stack's values only when the ARN's corresponding part is itself a token.
  • packages/aws-cdk-lib/aws-dynamodb/test/table-v2.test.ts: New test asserting no false-positive error when the source table ARN has a concrete account/region but a tokenized resourceName (string-concatenated from Lazy.string).

Backwards compatibility

Additive — the previous behavior only changed the extracted values when the entire ARN was fully concrete, which made validation tighter than intended (false errors). The new behavior extracts concrete components whenever possible and per-field checks still skip validation when a part is a token — preserving the documented "skip if token" behavior at the per-field level.

🤖🤖🤖 Generated with AI - this code was authored with the help of an AI agent.


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

@github-actions github-actions Bot added bug This issue is a bug. effort/small Small work item – less than a day of effort p1 labels Aug 3, 2026
@aws-cdk-automation
aws-cdk-automation requested a review from a team August 3, 2026 14:06
@github-actions github-actions Bot added the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label Aug 3, 2026

@aws-cdk-automation aws-cdk-automation left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@sanyamk23
sanyamk23 force-pushed the fix/dynamodb-table-v2-partial-arn-validation branch from 3ada80b to eba4d7f Compare August 3, 2026 17:43
@aws-cdk-automation
aws-cdk-automation dismissed their stale review August 3, 2026 20:30

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@sanyamk23

Copy link
Copy Markdown
Author

CI all green here. The build workflow is showing as action_required (GitHub fork protection needs a manual click on the Actions tab). Ready for review when someone has a moment.

@aws-cdk-automation aws-cdk-automation left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter fails with the following errors:

❌ Fixes must contain a change to an integration test file and the resulting snapshot.

If you believe this pull request should receive an exemption, please comment and provide a justification. A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed, add Clarification Request to a comment.

✅ A exemption request has been requested. Please wait for a maintainer's review.

@sanyamk23

Copy link
Copy Markdown
Author

Exemption Request: This fix addresses a bug where TableV2MultiAccountReplica incorrectly throws when the source table ARN is partially tokenized (concrete account/region but tokenized table name). The exact scenario is fully covered by unit tests in table-v2.test.ts ('TableV2MultiAccountReplica does not throw with partially tokenized source ARN'). Generating an integration test snapshot would require a full aws-cdk-lib build (~30 min) plus deployment against real AWS infrastructure. The fix is minimal and surgical — it only refactors how splitArn results are validated per-field instead of guarding on the entire ARN string. Given comprehensive unit test coverage and the complexity of producing meaningful integration snapshots for cross-account replication scenarios, we request an exemption from the integration test requirement.

@aws-cdk-automation aws-cdk-automation added the pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. label Aug 11, 2026
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Aug 14, 2026
@sanyamk23
sanyamk23 force-pushed the fix/dynamodb-table-v2-partial-arn-validation branch from 1a720d1 to e981f87 Compare August 17, 2026 12:19
@sanyamk23
sanyamk23 deployed to automation August 17, 2026 12:19 — with GitHub Actions Active
@sanyamk23
sanyamk23 deployed to automation August 17, 2026 12:19 — with GitHub Actions Active
@sanyamk23
sanyamk23 force-pushed the fix/dynamodb-table-v2-partial-arn-validation branch from e981f87 to 5796616 Compare August 17, 2026 19:52
@sanyamk23
sanyamk23 deployed to automation August 17, 2026 19:52 — with GitHub Actions Active
@sanyamk23
sanyamk23 deployed to automation August 17, 2026 19:52 — with GitHub Actions Active
…ross-repo PRs

When the GitHub API returns a 404 for the list reviews endpoint (which
can happen for cross-repo PRs from forks or when the PROJEN_GITHUB_TOKEN
lacks access to the source repository), treat it as no existing reviews
rather than crashing the entire validate-pr job.

Previously, the 404 error would propagate up to run().catch() in index.ts,
causing the process to exit with code 1 and failing the workflow.
…okenized

The previous broad `Token.isUnresolved(tableArn)` guard in
`validateMultiAccountReplica` skipped splitArn extraction whenever any
part of the source table ARN was tokenized, even if just the resourceName
was a token with concrete account and region components. This caused
`sourceAccount` and `sourceRegion` to fall back to the stack that owns
the imported resource (often the same as the replica stack), which
falsely triggered the `MultiAccountReplicaMustBeDifferentAccount` and
`MultiAccountReplicaMustBeDifferentRegion` errors for imported tables
whose ARN had a tokenized table name.

Now `splitArn` is always called and the extracted account/region are
used whenever they are concrete, falling back to the stack's values only
when the ARN's corresponding part is itself a token.

Closes aws#38354

🤖🤖🤖 Generated with AI - this code was authored with the help of an AI agent
@sanyamk23
sanyamk23 force-pushed the fix/dynamodb-table-v2-partial-arn-validation branch from 5796616 to 12f804c Compare August 17, 2026 19:57
@sanyamk23
sanyamk23 deployed to automation August 17, 2026 19:58 — with GitHub Actions Active
@sanyamk23
sanyamk23 deployed to automation August 17, 2026 19:59 — with GitHub Actions Active
@sanyamk23

Copy link
Copy Markdown
Author

Exemption Request - This fix corrects a false-positive validation error when a DynamoDB table ARN has a tokenized resourceName but concrete account/region. The change improves the existing validation logic without changing the public API. Unit tests thoroughly cover the validation behavior with various ARN patterns including tokenized parts. An integration test is not necessary as this is a validation logic fix, not a new feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/small Small work item – less than a day of effort p1 pr/needs-maintainer-review This PR needs a review from a Core Team Member pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(dynamodb): TableV2 validateMultiAccountReplica fails for imported table with tokenized ARN

2 participants