Fine grained row level access to Dynamodb via Cognito Authorizer

0

Im able to only allow logged in users to access my Api gateway endpoint via Cognito Authorizer. The next step is to allow users to only access their data in Dynamodb. For that Im taking the role ARN (which is defined in my user group) from the lambda request event, and assuming that role before querying Dynamodb. Here's my DynamoDB policy. If I hardcode the cognito user pool sub, which matches the portion key on the table, it works, which means my policy is correct. I just can't figure out how to dynamically get the user pool sub in the policy.

    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "dynamodb:DeleteItem",
                "dynamodb:GetItem",
                "dynamodb:PutItem",
                "dynamodb:Query",
                "dynamodb:Update*",
                "dynamodb:Delete*"
            ],
            "Resource": [
                "arn:aws:dynamodb:*:*:table/table-name-db",
                "arn:aws:dynamodb:*:*:table/table-name-db/index/*"
            ],
            "Condition": {
                "ForAllValues:StringEquals": {
                    "dynamodb:LeadingKeys": [
                        <NOT SURE WHAT TO ADD HERE>
                    ]
                }
            }
        }
    ]
}```
2回答
0
profile pictureAWS
エキスパート
回答済み 2年前
  • Thanks for your reply. "${cognito-identity.amazonaws.com:sub}" doesn't work unless you are using the indentity pool id as the partition key. In my case Im suing the user pool sub as partition key.

0

OK. I am not aware of how to accomplish this without using Cognito Identity Pools. This blog explains how you can use Cognito Identity Pools with Cognito User Pools to achieve fine-grained authorization - https://aws.amazon.com/blogs/mobile/building-fine-grained-authorization-using-amazon-cognito-user-pools-groups/

profile pictureAWS
エキスパート
回答済み 2年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ