The "Photo Upload" Pattern
Imagine building a photo-sharing app. A naive implementation routes every photo upload through your backend server: phone → your server → S3. Your server pays the bandwidth and CPU cost for every byte of every photo. With 10,000 active users, this becomes your biggest infrastructure cost.
The correct pattern: let the phone upload directly to S3 using temporary credentials. Your server is never in the data path. This is the canonical use case for Identity Pools.
The Mechanics
Here is the exact sequence of calls that happens when a user taps "Upload Photo":
- Login: The user authenticates with Cognito User Pool (or Google, etc.). The app receives a JWT (specifically the ID Token).
- Exchange: The app calls the Identity Pool endpoint (
GetCredentialsForIdentityorGetId+GetCredentialsForIdentity) and presents the JWT. - Verification: The Identity Pool validates the JWT signature against the identity provider's public keys. It resolves the user's stable Identity ID (a UUID that persists across sessions).
- Role Assumption: The Identity Pool calls AWS STS internally:
AssumeRoleWithWebIdentity, passing the JWT and the ARN of the Authenticated Role. - Credentials Issued: STS returns temporary credentials (Access Key, Secret Key, Session Token) to the Identity Pool, which forwards them to the app.
- Direct Access: The app uses these credentials to call
s3:PutObjectdirectly. AWS validates the SigV4 signature, checks the IAM policy, and allows the upload.
Security properties of the temporary credentials:
- Valid for 1 hour by default (configurable from 15 minutes to 12 hours via the IAM role's trust policy).
- Scoped to exactly the permissions defined in the Authenticated Role's policy.
- If stolen, they expire automatically — no revocation infrastructure needed.
- The session token is required alongside the access key; the access key alone is useless.
Interviewers frequently ask: "Why use Identity Pools instead of just putting AWS credentials in your mobile app?" The answer has two parts. First, hardcoded credentials in a mobile app can be extracted by anyone who decompiles the binary — this is a critical security vulnerability. Second, hardcoded credentials are permanent; if compromised, you must rotate them everywhere. Identity Pool credentials are temporary (1 hour), scoped to one user's permissions, and issued fresh each session. There is no credential to steal that has lasting value.