Amazon Cognito for User Authentication and Authorization. Every app you build needs to know who is using it and what they are allowed to do — this is the problem Cognito solves without forcing you to write complex login code from scratch. For the DVA-C02 exam, understanding the two parts of Cognito (user pools and identity pools) is essential because you will be asked to configure them for API Gateway and protect your backend resources.
Jump to a section
400 people are lined up outside a nightclub called "SecureApp". Each person must prove who they are, show their ticket (or buy one at the door), and decide if they want to stay on the dance floor or access the VIP lounge upstairs. The nightclub uses two separate checkpoints to manage all of this. At the front door, a bouncer named "User Pool" checks each person's ID and ticket. He verifies their identity and issues them a wristband that says "verified guest". He keeps a record of everyone who entered: their name, their age, and whether they are a VIP member. Once inside, guests can wander freely in the main area. But if someone wants to enter the VIP lounge (which has a bar, better music, and exclusive seating), they need to pass a second checkpoint. Another bouncer, named "Identity Pool", does not ask for ID again. He looks at the wristband from the first bouncer and then checks a clipboard that lists which specific VIP tables each guest is allowed to use. The clipboard is called an "IAM role" — it says "table 5, table 8, but not table 12". The visitor cannot get into the VIP lounge without the wristband from the first bouncer, and even with the wristband, they only get the specific tables they are authorised for. This is exactly how Amazon Cognito works: user pools handle who you are (authentication), and identity pools handle what you are allowed to do (authorisation). The nightclub never lets anyone skip the first bouncer, and it never gives anyone all-access passes — every guest gets exactly the permissions their wristband entitles them to.
Amazon Cognito is a fully managed service from AWS that handles user sign-up, sign-in, and access control for web and mobile applications. It means you do not have to build your own database of usernames and passwords, create your own login screens, or manage security tokens yourself. AWS does all that heavy lifting for you.
Cognito has two main components: a user pool and an identity pool. These two parts work together but do completely different jobs. A user pool is a directory of users. Think of it as your app's own private phonebook of everyone who has created an account. When a person signs up, Cognito stores their username, email, password (hashed and salted for security), and any other attributes you want, such as their phone number or date of birth. When they sign in later, Cognito verifies their password and, if correct, issues them a JSON Web Token (JWT). A JWT is just a small piece of data that acts like a digital ID card — it contains the user's username, the time they logged in, and when the token expires. The app can read this token to know who the user is without asking the database again.
An identity pool, on the other hand, does not store user information. Its job is to give temporary AWS credentials (like an access key and secret key) to authenticated users so they can access AWS services directly, such as reading a file from S3 or calling a DynamoDB table. The identity pool takes the JWT from the user pool (or another identity provider such as Google or Facebook) and exchanges it for temporary AWS credentials that have a limited set of permissions defined by an IAM role. IAM stands for Identity and Access Management, and it is the AWS system that controls who can do what. The identity pool assigns a role to the authenticated user based on their identity — for instance, all regular users get a role that can read files from a public folder, while admin users get a role that can delete files.
Why does this matter? Before Cognito existed, developers had to build their own authentication systems, which is notoriously difficult to get right. You had to hash passwords correctly, handle password resets, prevent brute-force attacks, manage token expiration, and ensure that tokens could not be forged. Cognito handles all of this for you. It also supports multi-factor authentication (MFA), which means requiring a code from an authenticator app or SMS message in addition to the password. MFA dramatically increases security because an attacker would need both your password and your phone to break in.
Cognito also integrates seamlessly with other AWS services. For the DVA-C02 exam, the most important integration is with API Gateway. API Gateway is a service that lets you create RESTful APIs that front-end apps call. You can configure API Gateway to validate the JWT from your Cognito user pool before a request reaches your backend code. This is called a custom authorizer or a Cognito user pool authorizer. If the token is missing, expired, or invalid, API Gateway rejects the request with a 401 Unauthorized response before any of your Lambda functions run. This protects your backend from unauthenticated traffic.
Another key concept is federated identities. This is the ability for users to sign in using existing accounts from Google, Facebook, Amazon, or Microsoft Entra ID (previously known as Azure Active Directory). Cognito can act as a bridge between these external identity providers and your app. When a user signs in with Google, Cognito receives a token from Google, verifies it, and then issues its own JWT for your app. The identity pool can then use that Cognito JWT to issue AWS credentials. This means users do not need a separate username and password for your app — they can use an account they already have.
Cognito also supports custom workflows through AWS Lambda triggers. For example, you can run a Lambda function after a user signs up to add their email to a marketing list, or before they sign in to check if their account has been suspended. These triggers are called "hooks" and they allow you to extend Cognito's behaviour without modifying its core code.
Finally, Cognito provides a hosted UI (user interface). This is a pre-built, branded sign-up and sign-in page that you can customise with your logo and colours. You do not have to write HTML or CSS for login screens — Cognito serves the page for you. The entire authentication flow happens on AWS infrastructure, which means you do not have to build, secure, or maintain any login pages yourself.
Create a user pool
In the AWS Management Console, navigate to Cognito and choose 'Create user pool'. You configure sign-in options (email, phone, username) and password policies. This creates the directory where your users will be stored.
Add an app client
Inside the user pool, create an app client that represents your mobile or web application. You set a client ID and client secret (if needed). The app uses this client ID when it talks to Cognito during sign-in.
Configure the hosted UI
Enable the hosted UI for your app client. You customise the domain name (like 'https://myapp.auth.us-east-1.amazoncognito.com') and the branding (logo, colours). This gives you a ready-made login page without any front-end coding.
Create an identity pool
Go to Federated Identities (Identity Pools) in Cognito and create a new pool. Link it to your user pool by providing the user pool ID and app client ID. Configure IAM roles for authenticated and unauthenticated users. This pool will issue temporary AWS credentials.
Set up API Gateway with a Cognito authoriser
In API Gateway, create or select your REST API. For each endpoint, choose 'Authorisation settings' and select 'Cognito' as the authoriser type. Provide the user pool ARN (Amazon Resource Name). API Gateway will now automatically validate JWTs on every request.
Test the end-to-end flow
Open the hosted UI URL in a browser, sign up a new user, verify the email, and sign in. After login, copy the access token from the URL. Use a tool like curl or Postman to call your API Gateway endpoint with the token in the 'Authorization' header. Confirm you get a 200 response. Then try calling without the token — expect a 401.
An IT professional building a mobile application for a healthcare startup would use Amazon Cognito in a very specific way. The app allows patients to view their lab results, book appointments, and message their doctor. The startup has three types of users: patients, doctors, and administrators. Each type needs different levels of access.
First, the developer creates a Cognito user pool called "HealthApp-Users". They configure it to require an email address and a password for sign-up. They enable MFA for all users because healthcare data is sensitive. They also set up custom attributes such as "role" (patient, doctor, admin) and "speciality" (for doctors only). When a patient signs up, Cognito sends a verification code to their email. Once verified, the user is stored in the user pool with a confirmed status.
Next, the developer creates an identity pool called "HealthApp-IdentityPool". They configure it to trust the user pool as an authentication provider. They also add Google as an additional provider so that users can sign in with their Google account if they prefer. The identity pool is given two IAM roles: one for unauthenticated users (which has almost no permissions) and one for authenticated users (which grants specific access to AWS resources).
Then the developer creates two API Gateway endpoints: one for retrieving lab results and one for posting appointment bookings. They attach a Cognito user pool authoriser to both endpoints. The authoriser is configured to validate the JWT from the HealthApp-Users user pool. If a request comes without a valid token, API Gateway returns a 401 response before any Lambda function runs.
The backend is a set of AWS Lambda functions that process the requests. When a Lambda function receives a request, it reads the user's role from the JWT claims. The claims are pieces of information embedded in the token, like the user's name and role. If the role is "patient", the function only returns lab results belonging to that patient. If the role is "doctor", the function returns lab results for all patients assigned to that doctor. If the role is "admin", the function can view and delete any record. This authorisation logic is implemented inside the Lambda function because the IAM roles from the identity pool only control access to AWS services, not to specific rows of data.
Finally, the developer uses the Cognito hosted UI for the login page. They customise the page with the healthcare startup's logo and colours. When a user opens the mobile app, it redirects them to the hosted UI. After successful login, Cognito redirects back to the app with tokens. The app stores the JWT locally and includes it in every API call to API Gateway. The entire experience feels seamless to the user, but behind the scenes, Cognito is managing all the security.
In this scenario, the IT professional did not write a single line of code for password storage, token generation, or MFA. They simply configured Cognito through the AWS Management Console or infrastructure-as-code tools like Terraform or AWS CloudFormation. The exam expects you to know exactly how to configure these settings to achieve the right security posture.
The DVA-C02 exam tests Amazon Cognito in three main ways: understanding the difference between user pools and identity pools, knowing how to integrate Cognito with API Gateway, and recognising the correct configuration steps for common scenarios. You will see at least 3-5 questions on this topic, and they are almost always scenario-based.
The most common question type gives you a description of an app that needs authentication and authorisation, then asks which combination of AWS services to use. A classic trap is confusing user pools with identity pools. Remember: user pools are for authentication (verifying identity), identity pools are for authorisation (giving AWS credentials). The exam loves to give you a scenario where the app only needs to verify who the user is (user pool only) versus a scenario where the user needs to access S3 or DynamoDB directly (user pool plus identity pool).
Another frequent question pattern involves API Gateway authorisation. The exam will describe an API that should reject requests without a valid login. The correct answer will involve configuring a Cognito user pool authoriser on the API Gateway method. A common trap is suggesting an identity pool instead, but identity pools do not validate tokens at the API Gateway level — they issue AWS credentials. Another trap is suggesting a Lambda custom authoriser when the question explicitly says tokens are from Cognito. The Cognito user pool authoriser is the simplest and most appropriate choice.
Key definitions you must memorise:
JWT (JSON Web Token): a secure token issued by Cognito after successful authentication.
Access token: used to authorise API calls.
ID token: contains user attributes, used to identify the user in your app.
Refresh token: used to get new access tokens without requiring the user to log in again.
IAM role: a set of permissions attached to the identity pool for authenticated and unauthenticated users.
Federated identity: using an external provider (Google, Facebook, Microsoft Entra ID) for sign-in.
Specific topics the exam tests heavily:
The flow from user pool to identity pool to AWS service.
The difference between authentication (user pool) and authorisation (identity pool).
How to set up a Cognito user pool authoriser in API Gateway.
The concept of hosted UI and customisation.
Lambda triggers: pre sign-up, post confirmation, pre authentication, etc.
Token expiration and refresh token rotation.
Common traps on the exam:
Confusing Cognito with IAM. IAM manages long-term users and roles for AWS accounts; Cognito manages temporary app users.
Assuming an identity pool can authenticate users — it cannot. It requires an authenticated token from a user pool or another provider.
Thinking you need to write your own token validation logic. Cognito and API Gateway handle it for you.
Forgetting that identity pools can assign different IAM roles for authenticated vs. unauthenticated users.
To prepare, practise with the AWS Management Console: create a user pool, add an app client, configure a hosted UI, then create an identity pool linked to it. Set up a simple API Gateway endpoint with a Cognito authoriser. Test the entire flow. Understanding this hands-on process is the best way to lock in the concepts for the exam.
Amazon Cognito user pools authenticate users and issue JWTs, but they do not grant access to AWS resources.
Amazon Cognito identity pools exchange a valid user pool token for temporary AWS credentials that are scoped through IAM roles.
API Gateway can validate Cognito JWTs using a Cognito user pool authoriser, rejecting unauthenticated requests before they reach your backend code.
Cognito supports federated sign-in through Google, Facebook, Amazon, and Microsoft Entra ID without requiring separate accounts in your app.
Cognito automatically handles password hashing, token expiration, and multi-factor authentication so you do not have to code these security features.
Lambda triggers allow you to run custom logic during sign-up, sign-in, and token generation events in Cognito.
The Cognito hosted UI provides a ready-made, customisable login page so you do not have to build one from scratch.
Refresh tokens in Cognito allow users to obtain new access tokens without re-entering their credentials, improving the user experience.
These come up on the exam all the time. Here's how to tell them apart.
Cognito User Pool
Stores user accounts and passwords (authentication)
Issues JWT tokens after sign-in
Does not provide access to AWS services directly
Cognito Identity Pool
Grants temporary AWS credentials (authorisation)
Requires an existing valid token from a user pool or social provider
Assigns IAM roles to control access to AWS services
Cognito User Pool Authoriser (API Gateway)
Validates JWT tokens directly without any custom code
Only works with tokens from a Cognito user pool
Simple to configure via the API Gateway console
Lambda Custom Authoriser (API Gateway)
Allows custom validation logic for any token type (OAuth, Keycloak, etc.)
Can call external services or databases to check authorisation
Requires writing and maintaining a Lambda function
Authentication
Verifies who the user is (identity check)
Uses passwords, biometrics, or social login
In AWS, handled by Cognito user pools or IAM users
Authorisation
Determines what the user is allowed to do (permissions)
Uses IAM policies and roles
In AWS, handled by IAM (and optionally Cognito identity pools)
JWT Access Token
Used to authorise API calls to protected resources
Contains scopes and permissions
Should be included in the Authorization header
JWT ID Token
Contains user attributes (name, email, picture)
Used to identify the user in the app front-end
Should not be shared with external APIs
Mistake
Cognito user pools and identity pools are the same thing and you always need both.
Correct
User pools handle authentication (verifying who you are). Identity pools handle authorisation (giving you AWS credentials to access services). You only need identity pools if your app needs direct access to AWS services like S3 or DynamoDB.
Beginners see two 'pools' and assume they always go together. Reading AWS documentation examples often shows both, but many apps only need one.
Mistake
Cognito stores passwords in plain text or encrypted format that developers can read.
Correct
Cognito never stores passwords in plain text. It uses a cryptographic hash function (bcrypt) to store a salted hash of the password. Developers cannot retrieve or view any user's password.
People new to security often think 'stored in the cloud' means the company can see it. AWS purposely designed Cognito so even AWS employees cannot see passwords.
Mistake
Once a user is authenticated by Cognito, they have full access to all AWS resources in the account.
Correct
Cognito only verifies identity. The user's permissions are controlled entirely by IAM roles assigned via the identity pool. Without those roles, an authenticated user has no AWS access at all.
Beginners confuse 'authenticated' (proven identity) with 'authorised' (granted permission). The exam punishes this confusion heavily.
Mistake
Cognito is only useful for mobile apps and cannot be used with web applications.
Correct
Cognito works with web apps, mobile apps, and even serverless backends. It provides a hosted UI that works in any browser, and libraries are available for JavaScript, Python, iOS, Android, and other platforms.
Cognito's mobile SDKs are heavily marketed, so beginners assume it is mobile-only. The hosted UI and web SDKs are less visible in tutorials.
Mistake
You can use Cognito identity pools without a user pool by using only social login providers like Google.
Correct
You can use identity pools with Google or Facebook directly — you do not need a Cognito user pool. However, the identity pool itself cannot authenticate users; it still requires a token from the external provider.
The phrase 'without a user pool' confuses beginners into thinking identity pools can authenticate on their own. They cannot.
Mistake
Cognito user pools can be used to grant access to EC2 instances directly.
Correct
Cognito user pools cannot grant access to EC2 instances. They are for app-level authentication. To grant AWS resource access, you must use an identity pool with IAM roles, and EC2 instances typically use IAM roles attached directly to the instance, not Cognito.
Beginners extrapolate 'user pool controls access' to mean all AWS resources, missing the fundamental separation between authentication and authorisation.
Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.
A user pool stores user accounts and handles sign-in (authentication). An identity pool gives those users temporary AWS credentials (authorisation) so they can access services like S3 or DynamoDB.
Yes, Cognito provides a hosted UI that you can customise with your own branding. You simply redirect users to the hosted UI URL, and Cognito handles the entire login flow.
Yes, both user pools and identity pools support federated identities. You can configure Google, Facebook, Amazon, Apple, and Microsoft Entra ID as identity providers, and users can sign in with their existing accounts.
API Gateway uses a Cognito user pool authoriser. You configure it with your user pool ARN, and it automatically validates the JWT's signature, expiration, and issuer on every incoming request before forwarding to your backend.
JWT stands for JSON Web Token. It is a small, self-contained packet of information that contains the user's identity and permissions. Cognito issues JWTs after successful login so that your app can verify the user's identity without repeatedly querying the database.
No, Cognito itself only handles authentication and token issuance. To restrict access to specific rows, you must use IAM role policies with conditions (like the 'dynamodb:LeadingKeys' condition key) or implement authorisation logic inside your Lambda functions.
You can use the admin set user password API or the forgot password flow. Cognito also supports an 'admin force change password' action that requires the user to set a new password on their next sign-in.
You've just covered Amazon Cognito for User Authentication and Authorization — now see how well it sticks with free DVA-C02 practice questions. Full explanations included, no account needed.
Done with this chapter?