AWS Builder Center

AWS IAM Explained: Practical Cloud Security for Beginners

Learn how AWS Identity and Access Management (IAM) helps secure cloud resources through users, roles, policies, and least-privilege permissions. Explore a practical S3 example, common security mistakes, and useful AWS tools to strengthen your cloud security knowledge.

AWS IAM Explained: Practical Cloud Security for Beginners

Introduction

Imagine that you are managing a company that uses AWS to host its website, store customer information, and run applications.
Your team has five developers. One developer manages the website, another works with databases, and the remaining developers build and test applications.
Would you give all five developers complete access to every resource in your AWS account?
Probably not.
If everyone has full access, a small mistake could have serious consequences. Someone might accidentally delete an important resource, modify a security setting, or access information they do not need.
This is where AWS Identity and Access Management (IAM) becomes important.
AWS IAM helps you control who can access your AWS resources and what actions they are allowed to perform.
In this article, we will explore IAM through practical examples, understand its major components, and learn how to apply the principle of least privilege when working with cloud resources.

1. What Is AWS IAM?

AWS Identity and Access Management, commonly known as IAM, is an AWS service that helps you manage access to your AWS account and resources.
It allows you to define permissions for different identities, including users and roles.
For example, consider an application hosted on Amazon EC2 that needs to read files from an Amazon S3 bucket.
Instead of giving the application unrestricted access to your AWS account, you can assign it an IAM role that allows it to read files from a specific bucket.
The application receives only the permissions required to perform its job.
This is an important cloud security practice: access should be controlled according to actual requirements.

2. Understanding the Four Main IAM Components

To understand IAM properly, you should become familiar with four important concepts.

A. IAM Users

An IAM user represents an identity in AWS with credentials that can be used to make authorized requests.
For example, a developer might need to work with certain AWS resources through the AWS Management Console or programmatically.
An IAM user can be created and granted the permissions required for that work.
However, creating a separate IAM user for every person is not always the best approach. For workforce access, AWS recommends using federation and IAM roles with an identity provider where appropriate.
For an individual learning AWS, it is also important to understand that the AWS account root user should not be used for everyday administrative activities.

B. IAM Groups

An IAM group allows you to organize IAM users who need similar permissions.
Imagine a company has ten developers working on the same application.
Instead of managing similar permissions separately for every developer, an administrator can create a group called  Developers  and attach an appropriate permissions policy to it.
Users in the group receive the permissions granted through that group.
Groups can make permission management easier, particularly when multiple users perform similar tasks.
Remember that IAM groups contain users, not other groups or IAM roles.

C. IAM Policies

IAM policies define permissions.
A policy specifies which actions are allowed or denied and under what conditions those permissions apply.
For example, a policy might allow a developer to retrieve files from an S3 bucket without allowing the developer to delete its contents.
IAM policies are commonly written in JSON format.
Here is a simple example of an identity-based policy that allows read access to objects inside one specific S3 bucket.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject"
],
"Resource": "arn:aws:s3:::my-example-bucket/*"
}
]
}
Let's understand the important fields:
  • Version: Specifies the policy language version.
  • Effect: Defines whether the statement allows or denies an action.
  • Action: Identifies the AWS operation covered by the policy.
  • Resource: Specifies the resource to which the permission applies.
In this example,  s3:GetObject  allows an authorized identity to retrieve objects from the specified bucket.
It does not grant permission to upload or delete objects.
The bucket name  my-example-bucket  is a placeholder. Replace it with your actual bucket name when adapting the example.
This policy also does not independently grant permission to list the bucket's contents. That would require an appropriate  s3:ListBucket  permission on the bucket resource, if listing is needed.

D. IAM Roles

An IAM role is an identity that can be assumed by an authorized user, AWS service, or other trusted entity to obtain temporary credentials.
Roles are particularly useful when an application needs permission to access another AWS service.
Consider this example:
You launch an application on Amazon EC2, and the application needs to read reports stored in Amazon S3.
You could configure the application with long-term access keys, but this creates additional security and maintenance responsibilities.
A better approach is to create an IAM role with the required S3 permissions and attach that role to the EC2 instance through an instance profile.
The application can then obtain temporary credentials through the AWS-provided credential mechanism.
This avoids the need to store long-term AWS access keys directly in the application code.
The key takeaway: IAM users, groups, policies, and roles serve different purposes, but together they help organizations manage access to AWS resources.

3. Understanding the Principle of Least Privilege

One of the most important concepts in cloud security is the principle of least privilege.
It means granting an identity only the permissions it needs to perform its assigned task.
Let's understand this through a practical example.
Suppose you are building a website that allows users to download PDF reports stored in an S3 bucket.
Your application needs to retrieve those reports.
Would it need permission to delete the entire bucket?
No.
Would it need permission to create new IAM users?
No.
Would it need administrator access to your AWS account?
No.
It needs only the permissions required to retrieve the relevant reports.
Granting additional permissions increases the potential impact of compromised credentials, application vulnerabilities, or accidental mistakes.
A practical way to apply least privilege is to:
  1. Identify what the user or application needs to accomplish.
  1. Determine the exact AWS actions required.
  1. Limit permissions to the necessary resources.
  1. Avoid unnecessary wildcard permissions.
  1. Review permissions periodically.
  1. Remove permissions that are no longer required.
Least privilege should not be treated as a one-time configuration. It is an ongoing security practice.

4. A Real-World Scenario: Securing an Application on AWS

Let's consider a simple online shopping application.
The application uses three AWS services:
  • Amazon EC2 to run the application.
  • Amazon S3 to store product images.
  • Amazon RDS to host the application's relational database.
Different components need different permissions.
For example, the application might need to retrieve product images from S3 and connect to its database.
However, it should not automatically receive permission to modify IAM policies, create new users, or delete unrelated resources.
A sensible design would include the following controls.
Step 1: Give the application an IAM role.
Attach an appropriately configured role to the EC2 instance so that the application can obtain temporary AWS credentials.
Step 2: Restrict S3 permissions.
Allow only the required S3 actions on the relevant bucket or objects.
Step 3: Protect database access separately.
Configure database authentication, network access, and database permissions appropriately. An IAM role does not automatically provide unrestricted access to an RDS database.
Step 4: Avoid unnecessary administrative permissions.
The application's role should not receive broad administrative access unless there is a clearly justified requirement.
Step 5: Monitor and review access.
Use appropriate AWS logging and monitoring services to investigate activity and review security configurations.
This example demonstrates an important principle: securing an application requires several controls working together. IAM is a major part of the solution, but it is not a replacement for database security, network security, or application security.

5. Try a Small IAM Exercise

If you are learning AWS, a small practical exercise can help you understand IAM more effectively than simply memorizing definitions.

Objective

Create a permissions policy that allows access to objects in a specific S3 bucket without granting unrestricted access to the account.

Step 1: Open the AWS Management Console

Sign in to your AWS account and open the IAM service.
Use an account with the appropriate permissions to create or manage IAM policies.

Step 2: Open Policies

Navigate to the Policies section and choose the option to create a policy.
Select the JSON policy editor if it is available in your console workflow.

Step 3: Add a Policy

Use the example policy from the earlier section.
Replace the placeholder bucket name with a bucket you are authorized to access.

Step 4: Review the Permissions

Check which actions the policy allows and which resources it covers.
Confirm that the policy does not accidentally grant unrelated permissions.

Step 5: Save and Test Carefully

Save the policy with a descriptive name, such as  S3ObjectReadOnlyExample .
Before attaching it to an identity, review the policy and consider using IAM Access Analyzer to help validate it.
If you attach the policy to a test identity, verify that the identity can perform the intended action and cannot perform actions that have not been authorized.
Remember that the effective permissions of an identity depend on all applicable policies and other authorization controls. A single policy does not necessarily determine the complete access decision.
Important: AWS usage can incur charges depending on the resources you create. This exercise focuses on IAM and S3 permissions; avoid creating unnecessary resources, and follow your organization's security rules if you are using a shared account.

6. Common IAM Mistakes Beginners Should Avoid

When learning IAM, it is easy to focus on making something work without considering whether the permissions are appropriate.
Here are several mistakes worth avoiding.

Mistake 1: Using the Root User for Everyday Tasks

The root user has extensive access to an AWS account.
Protect it with multifactor authentication and reserve it for tasks that specifically require root-user access.
Use an appropriately configured administrative identity for routine management.

Mistake 2: Giving Every Identity Administrator Access

Administrator permissions may make initial experimentation easier, but they can expose resources to unnecessary risk.
Grant only the permissions required for the task.

Mistake 3: Storing Access Keys in Source Code

Hardcoding AWS access keys in application code creates a security risk, especially if the code is uploaded to a public repository.
Prefer IAM roles and temporary credentials for supported AWS workloads.
Where long-term credentials are genuinely required, manage and protect them carefully.

Mistake 4: Forgetting That Permissions Can Overlap

AWS authorization can involve multiple policies and controls.
An identity might receive permissions through more than one applicable policy, while explicit denies and other authorization mechanisms can restrict access.
Therefore, do not assume that reviewing a single policy tells you everything about an identity's effective permissions.

Mistake 5: Never Reviewing Old Permissions

Applications change, employees change responsibilities, and temporary projects come to an end.
Permissions that were
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article