How to assign IAM role to users or groups
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
In the world of cloud computing and infrastructure management, managing permissions and access control is critical to ensuring security. AWS Identity and Access Management (IAM) is a service that helps you securely control access to AWS services and resources. One of the core features of IAM is the ability to attach policies to users and groups through IAM roles. This article provides a comprehensive guide on how to assign IAM roles to users or groups with detailed technical explanations and examples.
What are IAM Roles?
IAM roles are similar to IAM users in that they define a set of permissions for making AWS service requests. However, an IAM role does not have credentials associated with it (such as a password or access keys). Instead, IAM roles are intended to be assumed by entities such as users, groups, or services that need temporary permissions to carry out certain actions.
Advantages of Using IAM Roles
- Security: Provides temporary credentials, reducing the risk of credential theft.
- Flexibility: Roles can be assumed by different users or services, making them versatile.
- Granular Access Controls: Fine-tune permissions for specific actions.
Assigning IAM Roles to Users or Groups
Pre-requisites
- An AWS account with administrative privileges to access IAM services.
- Basic knowledge of IAM and AWS Management Console.
Steps to Assign IAM Role to Users or Groups
Step 1: Create an IAM Role
- Log in to the AWS Management Console and open the IAM console at https://console.aws.amazon.com/iam/.
- In the navigation pane, select Roles and click on Create role.
- Select the AWS service that will use this role. For example, if you want the role to be assumed by EC2, choose EC2.
- Click Next: Permissions.
- Attach appropriate policies. For example, if the role needs S3 access, attach the
AmazonS3FullAccesspolicy. - Proceed with the Next: Tags (optional) step to add metadata tags.
- Review all your choices and click on Create role.
Step 2: Assign IAM Role to a User or Group
Assign to a User
- Navigate to the IAM console, select Users in the navigation pane.
- Click on the specific user to whom you want to assign the role.
- Under the Permissions tab, click Add permissions.
- Select Attach existing policies directly or Add inline policy.
- Attach the policy that allows the user to
sts:AssumeRolefor the specific role. - Review and add permissions.
Assign to a Group
- Select Groups under the IAM console.
- Choose the necessary group where you want the role to be applicable.
- Repeat the same procedure as assigning a role to a user by adjusting permissions or policies attached to that group.
Example: Policy to Assume a Role
Here's an example JSON policy that grants a user permission to assume a specific IAM role:
- Least Privilege Principle: Always ensure the least permissions possible are granted to perform necessary tasks.
- Regular Audits: Periodically audit permissions and usage logs to maintain security posture.
- Role Management: Keep roles organized and delete unused roles to minimize security risks.
Related reading
- How to assume an AWS role from another AWS role?
- How to attach multiple IAM policies to IAM roles using Terraform?
- How to auto-scale Kubernetes Pods based on number of tasks in celery task queue?
- How to auto scale Amazon DynamoDB throughput?
- How to authenticate/authorize a consumer in Kafka for a topic before it consumes the message
- How to avoid buffer overflow on asynchronous non-blocking WSASend calls
- How to automatically scale up and scale down of micro services instances built using Spring Boot and Spring cloud?
- How to avoid having to enter image version in deployment yaml and use most recent image from azure container registry

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.