Skip to main content

IAM roles and temporary credentials

Why AWS recommends roles and short-lived credentials over long-term access keys, and how to apply that to people, applications, and other accounts.

4 min read · Last reviewed · SAA-C03

Loading your progress

Sign in to bookmark tutorials and track what you have read.

On this page

Why credentials matter

Every request to AWS is signed with credentials, and those credentials decide what the request is allowed to do. AWS credentials come in two broad kinds:

  • Long-term credentials, such as an IAM user's password and access keys, or the root user's sign-in details. They stay valid until someone changes or deletes them.
  • Temporary credentials, which you receive when you assume an IAM role. They expire on their own.

If long-term credentials leak, they keep working until someone notices. Temporary credentials limit that window. This is why AWS security guidance recommends relying on temporary credentials wherever possible.

The root user

Every AWS account starts with a root user that has complete access to every resource in the account, including billing. AWS recommends that you:

  • Do not use the root user for everyday work. Create administrative identities instead.
  • Do not create access keys for the root user.
  • Protect root sign-in with MFA (Multi-factor authentication)Signing in with two or more different kinds of proof, such as a password plus a code from a phone app or a security key. AWS recommends MFA for the root user and for every human user.Glossary entry (MFA). AWS requires MFA for the root user of every account type.
  • Keep the root user for the small set of tasks that only it can perform.

In AWS Organizations, you can go further and remove root user credentials from member accounts entirely.

Roles instead of shared users

An IAM role is an identity with permissions but without a long-term password or access keys. When a person or service assumes the role, AWS issues temporary security credentials for that session. Roles fit three common situations.

People

For a single AWS account, give people access through IAM roles rather than individual IAM users with long-term keys. For multiple accounts managed with AWS Organizations, AWS recommends IAM Identity Center, which manages workforce users and their permissions across accounts. Either way, everyone signs in with their own identity, which keeps actions traceable to a person.

Applications on Amazon EC2

An application running on an EC2 instance should not store access keys in its code, configuration files, user data, or machine image. Instead, attach an IAM role to the instance through an instance profile. The application then receives temporary credentials for the role, and they are rotated automatically.

An IAM role for an EC2 instance. An instance profile attaches an IAM role to the EC2 instance, and the application on it receives temporary credentials that are rotated automatically. The application uses them to send signed requests to Amazon S3, with no access keys stored anywhere.

Access across accounts

When an application in account A needs a resource in account B, account B creates a role that:

  1. Has a permissions policy granting only the access that is needed.
  2. Has a trust policy naming the PrincipalA person or workload that can make requests to AWS, such as an IAM user, a role session, the root user, a federated user, or an AWS service. Resource-based policies name the principals they allow.Glossary entry in account A that may assume it.

The application calls the AWS STS AssumeRole operation and receives temporary credentials for the role. Permissions in account A alone are not enough: the account that owns the resource must also allow the access.

Access across accounts. An application in account A asks AWS STS to assume a role in account B. STS checks that the role's trust policy names account A and returns temporary credentials to the application, which then uses them to access an S3 bucket in account B.

Least privilege

Whatever identity you use, grant only the actions and resources it needs. For example, an application that only uploads files to one prefix of an S3 bucket needs a single action:

{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Effect": "Allow",
			"Action": "s3:PutObject",
			"Resource": "arn:aws:s3:::amzn-s3-demo-bucket/uploads/*"
		}
	]
}

Broad managed policies such as AdministratorAccess or AmazonS3FullAccess are convenient, but they turn a small mistake into a large one.

Guardrails across many accounts

In AWS Organizations, service control policies (SCP (Service control policy)An AWS Organizations policy that sets the maximum permissions for IAM users and roles in member accounts. It grants nothing by itself, and it does not apply to the management account.Glossary entry) set the maximum permissions for IAM users and roles in member accounts, including the member account's root user. Two points are easy to miss:

  • An SCP never grants permissions. It only limits what identity-based and Resource-based policyA permissions policy attached to a resource, such as an S3 bucket policy or an SQS queue policy, that says which principals can use it, including principals in other accounts. Identity-based policies, in contrast, attach to users, groups, and roles.Glossary entry can allow.
  • SCPs do not affect users or roles in the organization's management account.

SCPs are preventive. A tool such as AWS Config, by contrast, detects and reports a noncompliant resource after it exists.

Key takeaways

  • Prefer temporary credentials from roles over long-term access keys.
  • Use the root user only for tasks that require it, protect it with MFA, and give it no access keys.
  • Give EC2 applications credentials through an instance profile, never through stored keys.
  • Use roles and AWS STS for cross-account access.
  • Use SCPs for organization-wide limits that account administrators cannot override.

Sources

Check your understanding

Loading your quiz progress

Sign in to check your understanding with 22 questions on AWS Identity and Access Management (IAM).

  • AWS Identity and Access Management (IAM) 6 min read

    AWS Identity and Access Management (IAM)

    Controlling who can do what in AWS: users, groups, and roles, the nine policy types, JSON policy elements, managed and inline policies, evaluation logic with implicit and explicit deny, permissions boundaries, cross-account access, federation, instance profiles, Roles Anywhere, ABAC, MFA, IAM Access Analyzer, credential reports, and best practices.

Glossary Install the app

LetMeMaster is an independent educational project and is not affiliated with or endorsed by Amazon Web Services. Practice results do not predict actual exam outcomes.

© 2026 LetMeMaster. All rights reserved. Content may not be copied or redistributed without permission.

Proudly made in Canada

Add LetMeMaster to your Home Screen

  1. Tap the Share button in your browser's toolbar. In Safari it is at the bottom of the screen, or at the top on iPad.
  2. Scroll down and tap Add to Home Screen.
  3. Tap Add. Open LetMeMaster from its icon on your Home Screen.