-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Imported DynamoDB TableV2 with fromTableArn does not get access to indexes with grantFullAccess #33896
Comments
When CDK use a resource using the fromXxx() method, it essentially builds a reference object with attributes on it. It's pretty much like you create a table out of CDK and now you need to reference it in your current CDK stack. In this case, CDK by default won't add or update any resource in this referenced resource. Now when you Root CauseThe issue stems from how hasIndex is determined when importing a table with fromTableArn():
aws-cdk/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2.ts Lines 448 to 450 in b855978
aws-cdk/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2-base.ts Lines 432 to 433 in b855978
Affected Codeaws-cdk/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2-base.ts Lines 426 to 440 in b855978
WorkaroundExplicitly provide the TableV2.fromTableAttributes(scope, id, {
tableArn: 'arn:aws:dynamodb:region:account:table/name',
grantIndexPermissions: true
}); Simple FixModify Making this a p2 and we welcome PRs. |
Thanks for looking at this. Just to clarify - this is not intended behaviour? But it can be circumvented using |
Hi, I checked the source, the default value of aws-cdk/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2.ts Lines 400 to 402 in 83449bc
|
Describe the bug
Related to 1540, but with a new caveat. There was previously a bug with granting constructs access to a table, where the policy it created would not grant access to any secondary indexes. This was addressed in PR 1564. Notably, I think this was before
TableV2
was introduced.However I have just found that, when importing with
cdk.aws_dynamodb.TableV2.fromTableArn
,grantFullAccess
still does not give adequate permissions for indexes in that case.Regression Issue
Last Known Working CDK Version
No response
Expected Behavior
grantFullAccess
should grant access to any indexes of the table.Current Behavior
grantFullAccess
does not access to any indexes of the table.Reproduction Steps
1: Create a table with an index in AWS.
2: Import the table into a construct with
fromTableArn
3: Do
grantFullAccess
to a lambda4: Try to access the index from the lambda - this will fail to due inadequate permissions.
Possible Solution
I presume either:
1 - The
ITableV2
created byfromTableArn
may not be aware of the indexes on the imported table, so did not add permissions for them.2 - Since
TableV2
is newer than the fix, this may have been a regression. However I have not tested a v1ITable
so I can't confirm this.Additional Information/Context
The table I imported where I discovered this is a couple of years old, and was originally created in AWS SAM, but that should not prevent this from working.
CDK CLI Version
2.1005.0 (build be378de)
Framework Version
2.181.1
Node.js Version
v20.15.1
OS
Ubuntu 24.04
Language
TypeScript
Language Version
5.6.3
Other information
This is the policy that was added:
Notably lacking any permissions for
/index
The text was updated successfully, but these errors were encountered: