
PEP and PDP for Secure Authorization with Cognito
Authorization is a critical part of securing cloud applications, and understanding the best practices for implementing it can make all the difference. In this post, we dig deep on the concepts of Policy Decision Points (PDPs) and Policy Enforcement Points (PEPs), and how they work together to manage user access efficiently. We dive into a serverless solution using AWS Lambda and API Gateway, implementing Role-Based Access Control (RBAC) for fine-grained access control based on Cognito User Groups.
Who are you?
When a user logs into our application, authentication ensures that they are who they claim to be. This could involve something as simple as a username and password or more complex multi-factor authentication (MFA).What can you do?
Authorization determines what resources, data, and actions a user is permitted to access based on their roles and permissions.aud
, iss
, and sub
). It then passes the claims to the PDP for a final decision on whether the user is authorized to access the requested resource.groups
claim in the JWT (from Cognito), and compares them against the permissions required to access a specific resource, stored in a data store. In our case we'll use DynamoDB.Admin
, User
, or Manager
) to access the resource (e.g., GET /admin
, POST /profile
). The PDP can also incorporate additional business logic, such as checking time-based access or geo-fencing.sub
, groups
, and role
) to the PDP for further authorization checks. In our solution we will actually forward the entire JWT token.- Check the user’s role (using the
groups
claim from Cognito). - Query a DynamoDB table that contains role-to-permission mappings (e.g., which roles have access to which API endpoints).
- Evaluates whether the user’s role matches the required permissions for the requested, resource or API endpoint.
read:profile
, write:profile
). The access token do not include the aud
claim.

Admin
, Developer
, and Test
. Click on Create Group
and give it a name. The group name would represent the Role that the user will have and determine what permission he/she will get, more on that setup further down.

cognito:groups
that our PEP and PDP will use later for permissions.Admin
, User
). SK (Sort Key): The resource, for example endpoint and Method e.g. GET /unicorn
. Action: The action e.g. GET, PUT, WRITE, READ, LIST etc Resource: The Resource, for example the endpoint /unicorn
Effect: The Effect, Allow or Deny Description: A description of the permission.PK | SK | Action | Resource | Effect |
---|---|---|---|---|
Admin | GET /unicorn | GET | /unicorn | Allow |
Test | POST /unicorn | POST | /unicorn | Allow |
Developer | DELETE /unicorn | DELETE | /unicorn | Deny |
cognito:groups
claim, and query the DynamoDB table to check if the role has permission to access the requested resource.