6.4 Amazon Cognito and Identity Federation

Key Takeaways

  • Cognito User Pools provide user sign-up, sign-in, and token management for web and mobile applications — it is a full-featured identity provider.
  • Cognito Identity Pools provide temporary AWS credentials for accessing AWS services directly from client applications (mobile, browser).
  • User Pools handle authentication (who are you?); Identity Pools handle authorization (what AWS resources can you access?).
  • Cognito supports social identity providers (Google, Facebook, Apple), SAML 2.0, and OIDC for enterprise federation.
  • Use User Pools + Identity Pools together: User Pool authenticates the user, Identity Pool grants temporary AWS credentials.
Last updated: March 2026

Amazon Cognito and Identity Federation

Quick Answer: User Pools = user directory for sign-up/sign-in (returns JWT tokens). Identity Pools = exchange tokens for temporary AWS credentials (access S3, DynamoDB from client apps). Use both together: User Pool authenticates → Identity Pool authorizes AWS access.

Cognito User Pools

A User Pool is a user directory for managing sign-up and sign-in for web and mobile apps.

FeatureDescription
Sign-up/Sign-inUsername/password, email, phone
Social loginGoogle, Facebook, Apple, Amazon
EnterpriseSAML 2.0, OIDC federation
MFASMS, TOTP (authenticator app)
Password policyConfigurable complexity requirements
TokensReturns ID token, Access token, Refresh token (JWT)
TriggersLambda triggers for custom logic (pre/post sign-up, pre/post auth)
Hosted UIAWS-hosted login page (customizable)
Advanced securityAdaptive authentication, compromised credential detection

Common Architecture: User Pool + API Gateway

  1. User signs in via Cognito User Pool → receives JWT token
  2. User sends JWT token with API requests
  3. API Gateway validates the token using Cognito authorizer
  4. If valid, request is forwarded to Lambda/backend

Cognito Identity Pools

An Identity Pool provides temporary AWS credentials to access AWS services directly.

FeatureDescription
InputTokens from User Pools, social providers, SAML, OIDC
OutputTemporary AWS credentials (access key, secret key, session token)
IAM rolesDefine different roles for authenticated vs. guest users
Fine-grained accessUse identity-based policies (e.g., user can only access their own S3 folder)
Guest accessOptional unauthenticated access with limited permissions

Common Architecture: User Pool + Identity Pool + S3

  1. User signs in via Cognito User Pool → receives JWT token
  2. Identity Pool exchanges JWT token for temporary AWS credentials
  3. Client uses credentials to upload files directly to S3
  4. IAM policy restricts access to user's own S3 prefix (/users/{cognito-identity-id}/*)

User Pools vs. Identity Pools

FeatureUser PoolIdentity Pool
PurposeAuthentication (who are you?)Authorization (what can you access?)
OutputJWT tokensAWS credentials (STS)
Use caseSign-in pages, user managementDirect AWS service access from clients
Without the other?Yes (API Gateway auth)Yes (with social/SAML tokens)
TogetherUser Pool authenticates → Identity Pool grants AWS access

Identity Federation Options

MethodUse Case
Cognito User PoolsWeb/mobile apps with user sign-up/sign-in
Cognito Identity PoolsTemporary AWS credentials for client apps
SAML 2.0 FederationEnterprise SSO with Active Directory
Web Identity FederationSocial login (Google, Facebook) → AWS access
IAM Identity Center (SSO)Centralized SSO for multiple AWS accounts

On the Exam: "Mobile app needs to upload photos directly to S3" → Cognito User Pool (auth) + Identity Pool (temp AWS creds) + S3 IAM policy. "Enterprise users need SSO to AWS Console" → IAM Identity Center with SAML.

Test Your Knowledge

A mobile application needs users to sign in and then upload photos directly to their own S3 folder. Which Cognito components are needed?

A
B
C
D
Test Your Knowledge

What does a Cognito User Pool return upon successful authentication?

A
B
C
D