Commit ac4e2d4
authored
chore(dynamodb): fix 5 failing integration tests (#36961)
### Issue # (if applicable)
N/A — Fixes 5 failing DynamoDB integration tests.
### Reason for this change
Five `aws-dynamodb` integration tests were failing due to:
- Hardcoded physical resource names causing `EarlyValidation::ResourceExistenceCheck` errors (name collisions)
- Hardcoded `env.region` preventing the integ-runner from controlling deployment regions
- A CloudFormation limitation where a replica cannot be created in the same stack operation that sets a resource-based policy
- A Lambda handler with hardcoded region and table name, and an assertion expecting `Payload` as an object when Lambda invoke returns it as a JSON string
### Description of changes
**integ.table-v2-global.ts / integ.dynamodb-v2.ondemand.ts** — Removed hardcoded `tableName: 'my-global-table'` to let CDK generate unique names, preventing `ResourceExistenceCheck` failures. Replaced hardcoded `env: { region: 'us-east-1' }` with `process.env.CDK_DEFAULT_REGION || 'us-east-1'` (global tables with replicas require a region-aware stack, but the region should come from the integ-runner rather than being hardcoded). Renamed the ondemand test's stack from `aws-cdk-global-table` to `aws-cdk-global-table-ondemand` to avoid collision with the provisioned test when running in parallel.
**integ.dynamodb.deletion-protection.ts** — Removed hardcoded `tableName: 'deletion-protection-test'`. Replaced the fragile `postDeploy` shell hook (which used CLI v2-only flags) with an `integ.assertions.awsApiCall('DynamoDB', 'updateTable', ...)` to disable deletion protection after deploy, enabling clean teardown. Removed explicit `env` to avoid cross-environment reference issues with the assertion stack.
**integ.dynamodb-v2.policy-ff.ts** — Deleted and converted to a unit test in `table-v2.test.ts`. CloudFormation does not allow creating a new replica in the same stack operation that has a resource-based policy on any replica — the error is `"A replica cannot be created in the same stack update as putting a resource-based policy on that new replica"`. This is a CloudFormation-level constraint (https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/rbac-considerations.html), not a CDK bug: the feature flag `resourcePolicyPerReplica` correctly scopes the policy to the primary region only (confirmed in `table-v2.ts:905-907`), but CloudFormation rejects the combination regardless.
A two-stack approach (table+replica first, then add policy) was also attempted but fails because `addToResourcePolicy` mutates the table's CFN resource in the original stack, so the replica and policy always end up in the same CloudFormation template. Since the test's intent is to verify that the feature flag scopes the policy to the primary replica and does not copy it to new replicas — a synth-time concern — it is better validated as a unit test using `Template.fromStack()`.
**integ.table-v2-replica.ts / replica-handler/index.py** — Replaced hardcoded `env: { region: 'us-east-1' }` with `process.env.CDK_DEFAULT_REGION || 'us-east-1'`. Added `TABLE_NAME` and `REPLICA_REGION` environment variables to the Lambda function, and updated the Python handler to read from `os.environ` instead of hardcoding `'global-table'` and `'us-west-1'`. Fixed the assertion to use `Match.stringLikeRegexp('status_code.*200')` since Lambda invoke returns `Payload` as a JSON string, not a parsed object.
### Describe any new or updated permissions being added
None
### Description of how you validated changes
The 4 remaining integration tests deployed and passed via `integ-runner`:
```bash
yarn integ \
test/aws-dynamodb/test/integ.table-v2-global.js \
test/aws-dynamodb/test/integ.dynamodb.deletion-protection.js \
test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js \
test/aws-dynamodb/test/integ.table-v2-replica.js \
--disable-update-workflow --update-on-failed --force \
--parallel-regions us-east-1 us-west-2 --verbose
```
Regions: us-east-1, us-west-2 (parallel-regions), with replica regions us-east-2, us-west-1, eu-west-1.
The converted unit test passes:
```bash
npx jest aws-dynamodb/test/table-v2.test.ts -t "resourcePolicyPerReplica"
```
### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)
----
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*1 parent 5441a51 commit ac4e2d4
48 files changed
Lines changed: 61699 additions & 25279 deletions
File tree
- packages
- @aws-cdk-testing/framework-integ/test/aws-dynamodb/test
- integ.dynamodb-v2.ondemand.js.snapshot
- integ.dynamodb-v2.policy-ff.js.snapshot
- integ.dynamodb.deletion-protection.js.snapshot
- asset.3c1a88b76a71a46d4ce11a1351848c7dca61a2e2d8bc9933d0a619c1fce17bff.bundle
- integ.table-v2-global.js.snapshot
- integ.table-v2-replica.js.snapshot
- asset.4dc53751ed80274daf175efeff9265dbc5cca7f749c3bdceaf70bc630eaec6d1.bundle
- replica-handler
- aws-cdk-lib/aws-dynamodb/test
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | | - | |
182 | 181 | | |
183 | 182 | | |
184 | 183 | | |
| |||
This file was deleted.
Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments