Security · Topic 1 of 6
Federation, Assumed Roles and Programmatic Access
How a developer gets temporary AWS credentials: identity federation, assuming IAM roles, the SDK credential chain and Signature Version 4 signed calls.
- 5 min
- Includes a diagram
- Federation exchanges an outside identity for temporary credentials. Cognito user pools return tokens, and identity pools return AWS credentials.
AssumeRolereturns an access key ID, secret access key, session token and expiration.- A cross account assume needs a trust policy on the role and an allow in the caller's identity policy.
What it is
Every call to an AWS API must be signed with credentials. The safest credentials are temporary: an access key ID, a secret access key and a session token that expire on their own.
This page covers four skills that all lead to the same goal. Federation lets users from another identity system get AWS access. Assuming a role is the mechanism that hands out the temporary credentials. Programmatic access is how your code finds them, and a signed call is how it uses them.
How it works
Identity federation
Federation means users sign in with an identity that lives outside IAM and still receive AWS permissions through an IAM role.
| Need | Use | What the app receives |
|---|---|---|
| Customers sign in to your web or mobile app | Amazon Cognito user pool | JSON Web Tokens (ID, access and refresh tokens) |
| Those customers must call AWS services directly | Amazon Cognito identity pool | Temporary AWS credentials for an IAM role |
| Employees sign in with a corporate directory | AWS IAM Identity Center | Temporary credentials for a permission set |
| An existing SAML 2.0 or OIDC provider | IAM identity provider plus a role | Credentials from AssumeRoleWithSAML or AssumeRoleWithWebIdentity |
A user pool authenticates and returns tokens. It does not give AWS credentials. An identity pool takes a token from a user pool, a social provider or a SAML or OIDC provider and exchanges it for AWS credentials. It can also issue guest credentials for unauthenticated users, mapped to a separate, more restricted role.
AssumeRoleWithSAML and AssumeRoleWithWebIdentity need no AWS credentials to call, because the identity provider's token is the proof.
Assuming a role
A role has no password or long term keys. A caller asks the AWS Security Token Service (STS) to assume it by calling AssumeRole. STS returns temporary credentials with an expiration time.
Two policies must agree. The role's trust policy names who may assume it. The caller's own identity policy must allow sts:AssumeRole on the role. For a different account, both sides must allow it.
- External ID: a shared value that a third party supplies when assuming your role. It protects against the confused deputy problem.
- Session duration: the default is one hour. A role can set a maximum session duration of 1 to 12 hours. Role chaining (a role assuming another role) is limited to one hour.
- Passing a role to a service: to attach a role to Lambda, ECS or EC2, your identity needs
iam:PassRolefor that role.
Programmatic access
Code finds credentials through the credential provider chain. The SDK checks sources in a fixed order and uses the first one that works. In general, environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN) come before shared files, and container or instance credentials come last.
| Where the code runs | Credential source |
|---|---|
| Lambda | Execution role, delivered as environment variables |
| EC2 | Instance profile through the instance metadata service |
| ECS | Task role through the container credentials endpoint |
| Developer laptop | A profile in ~/.aws/config, often IAM Identity Center (aws configure sso, then aws sso login) |
A profile can include role_arn and source_profile, and the SDK then calls AssumeRole for you and refreshes the credentials.
Authenticated calls
AWS APIs use Signature Version 4 (SigV4). The SDK and CLI sign every request for you, using the credentials, the Region, the service name and a timestamp. When you call a service with a raw HTTP client, such as an API Gateway endpoint that uses IAM authorization, you must sign the request yourself with the service name execute-api.
How the exam asks about this
- "A mobile app must let signed in users upload directly to an S3 bucket with least privilege" -> a Cognito user pool for sign in plus an identity pool that issues temporary credentials for a scoped role.
- "A Lambda function needs to call a service in another account" -> assume a role in that account with
AssumeRole; the role's trust policy must trust the function's execution role. - "A script on an EC2 instance contains an access key and fails an audit" -> remove the key and use an instance profile.
What to remember for the exam
- Federation exchanges an outside identity for temporary credentials. Cognito user pools return tokens, and identity pools return AWS credentials.
AssumeRolereturns an access key ID, secret access key, session token and expiration.- A cross account assume needs a trust policy on the role and an allow in the caller's identity policy.
- Use an external ID when a third party assumes your role.
- Never hard code access keys. Use the execution role, instance profile, task role or IAM Identity Center.
- The SDK signs requests with SigV4. Raw HTTP calls to IAM protected endpoints need manual signing.
An ExpiredToken error means the temporary credentials ran out. Fix it by letting the SDK refresh through the credential chain, not by creating a long term key.
Common mistakes
Confusing the two Cognito pools. A user pool proves who the user is and returns tokens. Only an identity pool returns AWS credentials, so a user pool alone cannot give direct access to S3.
Forgetting one side of the trust. Assuming a role fails with AccessDenied when the role's trust policy does not name the caller, or when the caller's own policy lacks sts:AssumeRole.
Putting keys in code or in a container image. Long term keys leak through source control and images. Use the credential chain instead.
Check yourself
Which Cognito component exchanges a sign in token for AWS credentials?
The identity pool. A user pool only authenticates users and returns tokens.
What two things must allow a cross account
AssumeRolecall?The trust policy of the target role and the caller's identity policy (
sts:AssumeRole).How does an application on EC2 get credentials without stored keys?
Through an instance profile, which the SDK reads from the instance metadata service.
Topic 1 of 6 in Security
Test yourself on Security
The full AWS DVA-C03 question bank has 850 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by AWS. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.