-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
[aws-dynamodb] Creating a new Table using fromTableName returns a Table object that doesn't include secondary indexes #11445
Comments
Hello @alonjupiter , thanks for opening the issue. Thanks, |
Hi @skinny85, Thanks for the quick response. Now you mention it does make sense that CDK will not be able to import all of its attributes just be referring to it by name. That said, I ran a quick test today to see if this can be worked around by explicitly defining the table's GSIs using This the code I used: Table.fromTableAttributes(this, "MyTable", {
tableName: "MyTable",
globalIndexes: ["foo", "bar"],
}).grantReadData(lambdaFn); When I tried to deploy my stack the IAM statement warned me of the following changes:
It looks as if the IAM role generated for the Lambda function is too permissive as it will grant permissions to all GSIs, while I explicitly stated only 2 out of 4 GSIs. Is this too the expected behaviour? |
Hi @alonjupiter , yes, this is the expected behavior. I believe it's done that way, because you don't know the names of indexes before they are deployed in the case of a new Table. In general, we don't assign per-index permissions - seems a little overkill I think...? Let me know if you disagree. |
Hi @skinny85! I'd say I disagree. Generally speaking the security posture approach advocated by AWS is is to always go on the path of least privilege and only give access to the services/features/indices that are needed for that specific function or job. Granting too permissive permissions to a resource goes against the above, and therefore this behavior should be amended to grant resources the least permissive permissions by default. Happy to further discuss if needed! |
OK. Let's change this to a feature request then 🙂. |
Great stuff, thank you @skinny85! |
No problem @alonjupiter . BTW, Pull Requests are very welcome 😉. https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md |
@skinny85 Is this feature request has been moved?, I'm planning to start work on it |
If by "moved", you mean "has someone started working on it", then the answer is "No". It's all yours 🙂. |
@skinny85 Yes, Thanks for the update. |
This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
FYI looks like specifying aws-cdk/packages/aws-cdk-lib/aws-dynamodb/lib/table.ts Lines 633 to 640 in edad593
|
Hello!
I’ve noticed some discrepancies between the behavior of a
dynamodb.Table
created asnew Table()
and ones that are created by usingTable.fromTableName()
Using
new Table(...).grantReadWriteData(myLambdaFunction)
delegates permissions to the primary table index, alongside all available GSIs.However, using
new Table.fromTableName(…).grantReadWriteData(myLambdaFunction)
seems to delegate permissions to the primary table index only.Reproduction Steps
What did you expect to happen?
Lambda function should be granted permissions to
ReadWrite
to all of the table's indexes, both primary and LSIs/GSIs.What actually happened?
Lambda function was granted permissions to
ReadWrite
to the primary index only.Environment
Other
To workaround this issue one could explicitly define all partitions and then grant the necessary permissions to each, as such:
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: