Skip to content

Commit ac4e2d4

Browse files
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

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/aws-cdk-global-table.assets.json renamed to packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/aws-cdk-global-table-ondemand.assets.json

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/aws-cdk-global-table.template.json renamed to packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/aws-cdk-global-table-ondemand.template.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@
178178
"StreamSpecification": {
179179
"StreamViewType": "NEW_AND_OLD_IMAGES"
180180
},
181-
"TableName": "my-global-table",
182181
"TimeToLiveSpecification": {
183182
"AttributeName": "attr",
184183
"Enabled": true

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/awscdkglobaltableintegDefaultTestDeployAssertA2A9E81F.assets.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.policy-ff.js.snapshot/tablev2resourcepolicyintegtestDefaultTestDeployAssertBE3353C7.assets.json renamed to packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/awscdkglobaltableondemandintegDefaultTestDeployAssert303D85DB.assets.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/awscdkglobaltableintegDefaultTestDeployAssertA2A9E81F.template.json renamed to packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/awscdkglobaltableondemandintegDefaultTestDeployAssert303D85DB.template.json

File renamed without changes.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/cdk.out

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-dynamodb/test/integ.dynamodb-v2.ondemand.js.snapshot/integ.json

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

Comments
 (0)