Course menuDVA-C03

Exams / DVA-C03 / Study guide / Amazon Cognito and federated access

Amazon Cognito and federated access: DVA-C03 study notes and practice questions

What to know about Amazon Cognito and federated access for the DVA-C03 exam, from the Security domain (26% of the exam guide), then 3 free questions to test it. Part of the DVA-C03 study guide.

Last verified against current AWS documentation ·How we write our questions

What to know for the exam

These questions describe an app, its users and the AWS resources it touches, then ask how users should prove who they are and what they may reach.

User pools and identity pools

A user pool is a user directory. It handles sign-up, sign-in and MFA, and it returns three tokens: the ID token (who the user is), the access token (carries OAuth scopes and authorizes calls to your API or to the user pool’s own operations) and the refresh token (gets new tokens). Your API can check a user pool token, for example with an Amazon API Gateway Cognito authorizer: send the ID token when the method has no OAuth scopes, and the access token when it requires a scope. A user pool token does not give access to AWS services. A user pool can also federate social, SAML and OIDC providers and still issue its own tokens, so the backend sees one token format.

An identity pool exchanges an identity from a user pool, a social provider, or a SAML or OIDC provider for temporary AWS credentials. It does this by assuming an IAM role: an authenticated role for signed-in users and, if you turn it on, an unauthenticated role for guests.

Use the pair this way:

  • A user pool alone when users sign in to reach your own API.
  • A user pool plus an identity pool when a browser or mobile app must call S3, DynamoDB or another AWS service directly with temporary credentials.
  • An identity pool with the unauthenticated role for guests who may read public content and nothing else.

Groups and role mapping

Each user pool group can be linked to an IAM role with a precedence value. The ID token’s cognito:preferred_role claim names the role of the group with the lowest precedence value, and an identity pool set to choose role from token uses that claim. Roles are not merged.

Per-user data in S3

You do not need one role per user. Write one role’s policy against the resource with an identity variable, such as ${cognito-identity.amazonaws.com:sub}, so each user can reach only a folder named after their own identity ID. This is the usual answer when the wording says “each user, only their own folder.”

Client secrets and public apps

A browser or mobile app cannot keep a secret. Create the app client without a client secret and use the authorization code grant with PKCE. A secret cannot be removed from or added to an existing app client, so create a new one. Give a client secret only to a server-side app, such as a machine-to-machine client using the client credentials grant, which returns only an access token.

MFA and triggers

A user pool can set MFA to off, optional or required, with TOTP, SMS or email codes. Federated users are authenticated by their own identity provider, so the pool’s MFA setting does not apply to them.

Lambda triggers run code at set points: pre sign-up can reject a new user, post confirmation runs after a self-signed-up user confirms (a good place to create a profile), pre token generation adds or changes claims at sign-in and refresh, and migrate user moves users from an old directory on their first sign-in. Custom attributes cannot be renamed, deleted or changed in type after they are created.

How to choose

Scenario wording Answer
Sign users in and protect an API User pool, with an authorizer on the API
Mobile app writes to S3 with temporary credentials User pool and identity pool
Guests read public objects Identity pool, unauthenticated role
Different access for different user groups User pool groups mapped to IAM roles
Each user only sees their own objects One role with an identity variable in the resource ARN
Corporate SAML or OIDC login Federation through the pool
Reject sign-ups from unapproved domains Pre sign-up trigger
Add a tenant claim to every token Pre token generation trigger
Keep users signed in without a password Refresh token

Common traps

  • A client secret in a browser or mobile app.
  • Expecting a user pool token to grant AWS service permissions.
  • Using an identity pool to check who calls your own API, instead of a user pool token.
  • Giving each user an IAM user with long-term access keys.
  • Assuming group permissions combine. Only one group’s role applies.

Try the 3 practice questions

A fitness app for mobile devices lets members sign up and sign in with an email address and password.

After sign-in, the app must read and write the member's own folder in an Amazon S3 bucket, using temporary AWS credentials that cover only that folder. The app must not hold any AWS keys.

Which Amazon Cognito setup meets these requirements?

Choose one answer.

  1. A. A user pool only, with the app sending the user pool ID token to S3 with each request, so that S3 can check the member's folder.
  2. B. A user pool for sign-in, and an identity pool that exchanges the tokens for temporary credentials of a role limited to the member's folder.
  3. C. An identity pool only, with members signing up directly in the identity pool using their email address and password, and getting credentials at once.
  4. D. A user pool with an app client secret built into the app, and that secret used to sign every S3 request made on the member's behalf.
Show the answer and explanation

Answer: B

  • A. Wrong: S3 does not accept Cognito tokens. AWS service calls must be signed with AWS credentials, and a user pool alone does not provide those.
  • B. Right: Correct. The user pool authenticates the member and issues tokens. The identity pool trades those tokens for temporary AWS credentials, using a role whose policy covers only that member's folder. Learn more: Amazon Cognito identity pools (opens in a new tab)
  • C. Wrong: Identity pools do not hold a user directory or handle sign-up. They trust identities from providers such as user pools and issue AWS credentials for them.
  • D. Wrong: An app client secret authenticates the app to the user pool. It is not an AWS credential, and it must not be built into a mobile app.

Explanation

User pools answer who the user is by authenticating them and issuing tokens. Identity pools answer what AWS resources the user may use, by exchanging a trusted token for temporary credentials with a limited role. Apps that call AWS services directly usually combine the two.

Cognito user pool sign-in, then identity pool credentials for S3 The mobile app, which holds no AWS keys, signs the user in with a Cognito user pool and gets an ID token. A Cognito identity pool exchanges the token for temporary credentials of an IAM role. The role allows access only to the user's own prefix in the S3 bucket. Mobile app no AWS keys email and password Cognito user pool sign-in checks the password, returns an ID token Identity pool token exchange trades the token for temporary credentials S3 bucket user's own prefix role allows only this user's prefix
The user pool says who the member is. The identity pool turns that into short-lived credentials for one folder.

Study

A museum's mobile app lets visitors browse exhibit photos stored under the public-gallery/ prefix of an Amazon S3 bucket before they register.

Visitors have not signed in, the app must not contain long-term AWS credentials, and access must be read-only and limited to that prefix.

Which solution meets these requirements?

Choose one answer.

  1. A. An IAM user with read access to the prefix, whose access key is built into the app so that every visitor can use it.
  2. B. A Cognito identity pool that allows guest access, mapped to an IAM role that permits s3:GetObject on the prefix only.
  3. C. A Cognito user pool with one shared guest account that every visitor uses to sign in to the app.
  4. D. A bucket policy that lets any principal call s3:GetObject on every object in the whole bucket.
Show the answer and explanation

Answer: B

  • A. Wrong: A key built into an app can be extracted and reused by anyone, and it does not expire. This breaks the rule against long-term credentials in the app. Temporary credentials issued to guests are the safer way to give anonymous users limited access. Learn more: Amazon Cognito identity pools (opens in a new tab)
  • B. Right: Correct. An identity pool can issue temporary AWS credentials to users who have not signed in, using a role that you scope down. Limiting the role to s3:GetObject on one prefix gives read-only access to just those photos. Learn more: IAM roles for identity pools (opens in a new tab)
  • C. Wrong: A user pool authenticates people and returns tokens, but it does not hand out AWS credentials by itself. A shared account also removes any way to tell visitors apart. A guest role in an identity pool is the feature built for unsigned-in users. Learn more: Amazon Cognito identity pools (opens in a new tab)
  • D. Wrong: Public read access needs no credentials, so it cannot meet the temporary credentials requirement. It is also wider than one prefix and exposes every object in the bucket. A bucket policy limited to the prefix would narrow it, but guests would still receive no credentials.

Explanation

Cognito identity pools can give temporary, scoped-down AWS credentials to guests as well as to signed-in users. The guest role is limited to s3:GetObject on one prefix, so nothing long-lived ships in the app and visitors cannot read other objects. User pools, embedded keys and public bucket policies each miss at least one requirement.

Study

A fitness company's web and mobile apps let customers sign in with an email address through an Amazon Cognito user pool, and its backend APIs validate the user pool's tokens.

Marketing now wants customers to be able to sign in with their Google or Apple accounts as well. The backend must keep validating the same tokens, and customer profiles must stay in one place.

Which solution meets these requirements?

Choose one answer.

  1. A. Create an identity pool that trusts Google and Apple, and have the apps exchange those logins for AWS credentials.
  2. B. Create one extra user pool for each social provider and update the backend to trust the tokens from all three pools.
  3. C. Add Google and Apple as social identity providers in the existing user pool and send users through the pool's sign-in pages.
  4. D. Keep the user pool for email sign-in and add an API Gateway Lambda authorizer that validates Google and Apple tokens directly.
Show the answer and explanation

Answer: C

  • A. Wrong: An identity pool returns temporary AWS credentials, not user pool tokens, so the backend would have to change how it validates callers. It also leaves profiles outside the user pool. Federating through the user pool keeps the token format unchanged. Learn more: Amazon Cognito identity pools (opens in a new tab)
  • B. Wrong: Three pools means three issuers and three sets of signing keys for the backend to trust, which changes token validation. Profiles would also be split across pools. Social sign-in can be added to the existing pool instead.
  • C. Right: Correct. The user pool handles the exchange with the social provider and then issues its own tokens, so the backend sees the same kind of token however the user signed in. Federated users also get a profile in the same pool. Learn more: Social sign-in with user pools (opens in a new tab)
  • D. Wrong: This would work, but the backend then receives two kinds of identity and the team must write and maintain token validation for each provider. Profiles for social users would also sit outside the pool. Letting the user pool federate the providers avoids that code. Learn more: Lambda authorizers for REST APIs (opens in a new tab)

Explanation

A Cognito user pool can federate social identity providers and then issues its own standard tokens, so the backend does not change and profiles remain in one pool. An identity pool returns AWS credentials rather than user pool tokens. Extra pools or custom authorizers add issuers and code to maintain.

Study

Want more on Amazon Cognito and federated access? The 5 full-length practice sets have 15 more Amazon Cognito and federated access questions, 390 in all, none of them in the free exam. One payment of $14.99, no subscription. See the practice sets

Study Amazon Cognito and federated access

More Security topics