IAM Roles (original) (raw)

Last Updated : 2 Aug, 2025

AWS IAM Roles allow users, applications and services to securely access resources without requiring permanent credentials. Unlike IAM users, which are assigned to specific individuals, roles can be temporarily used by AWS services like EC2 and Lambda or even by external entities. This approach helps businesses manage permissions more efficiently while ensuring security best practices, such as granting access only when necessary.

**Reason to Use IAM Roles in AWS

IAM Roles eliminate the need to hardcode AWS access keys and secret keys within your applications. Instead, roles are assumed temporarily by trusted entities (like EC2, Lambda, or EKS), allowing them to perform actions based on defined permissions.

**For example:

This model enhances security, scalability, and compliance.

Core Components of IAM Roles

iam_role

IAM Roles are made up of the following:

**Types of IAM Roles

types_of_iam_roles

IAM Roles in AWS help control access to resources without using permanent credentials. Depending on the use case, different types of roles serve different needs:

1. **Service Roles

These are custom roles created by administrators to allow an AWS service (like EC2, Lambda, or CloudFormation) to access resources in your account on your behalf. You define both the **trust policy (which service can assume the role) and the **permissions policy (what actions the service can perform).

2. **Service-Linked Roles

Predefined and managed automatically by AWS for specific services. These roles come with all required permissions for the service to function correctly and **cannot be modified by the user. They are automatically created or updated by the service when needed.

3. **Cross-Account Roles

Allow users, services, or identities from one AWS account to assume a role in another account. This enables secure access across accounts without needing duplicate IAM users. The trust policy specifies the external account, and the permissions policy defines allowed actions.

4. **Federated Roles

Used for identity federation via SAML or OpenID Connect. These allow users from **external identity providers (e.g., Google, Okta, Active Directory) to assume roles in AWS without needing separate credentials.

5. **Web Identity (OIDC) Roles

Designed for mobile and web applications, these roles allow apps authenticated through **OIDC providers (e.g., Cognito, Facebook) to access AWS resources. Users assume roles using web-identity tokens with STS operations like AssumeRoleWithWebIdentity.

6. **Custom Roles (User-Assumable Roles)

These are fully **custom IAM roles created to be assumed by IAM users (in the same account) or other roles. Often used to grant temporary elevated permissions (e.g., admin privileges) when needed.

IAM Role Vs. IAM User

IAM Roles and IAM Users are both used to manage access to AWS resources, but they serve different purposes. Here’s how they compare:

IAM Role IAM User
1. A temporary identity that users, applications, or AWS services can assume when needed. 1. A permanent identity assigned to an individual with specific credentials.
2. Uses temporary security credentials that expire and automatically refresh. 2. Uses a fixed password for AWS console access or long-term access keys for API/CLI.
3. Best for allowing AWS services (like EC2 and Lambda) or external users to access resources without storing credentials. 3. Best for individuals who need direct and continuous access to AWS.
4. More secure because it doesn’t require storing long-term credentials. 4. Less secure if access keys are not rotated regularly or get exposed.
5. Can be used by multiple users, AWS services, or external entities temporarily. 5. Assigned to a specific person with fixed permissions.
6. Users or AWS services assume the role when needed, gaining the required permissions for a limited time. 6. The user logs in with a password or uses access keys for authentication.
7. An EC2 instance needs temporary access to an S3 bucket. 7. An administrator needs permanent access to manage AWS resources.

Common Issues and Troubleshooting with IAM Role

Common IAM role issues and troubleshooting tips:

1. **Role won't be assumed due to wrong trust policy

2. **Role Permissions aren't enough

3. **Session duration too short

4. **Resource-based policies blocking Role Access

5. **MFA not set up for sensitive Roles

6. **Changes to Permissions not taking effect right away

7. **Role can't be assumed because MFA is missing

8. **Wrong role assigned to EC2 or other Services

9. **Cross-Account Access not working

10. **Role Session expired unexpectedly