IAM Users and Policies: A Guide to Least Privilege
Learn to manage AWS access with IAM users and policies. Master the principle of least privilege to keep your cloud infrastructure secure and well-architected.
Previously in this course, we covered configuring the AWS CLI. Now that you can communicate with AWS from your terminal, we need to ensure that the identity you are using follows the Principle of Least Privilege—the security practice of granting only the minimum permissions necessary to perform a task.
Understanding IAM Fundamentals
Identity and Access Management (IAM) is how AWS manages authentication (who you are) and authorization (what you can do).
An IAM User represents a person or a service that interacts with AWS. When you first set up an AWS account, you use the "root user," which has unrestricted access. Using the root user for daily development is a significant security risk. Instead, we create IAM users with specific permissions.
IAM Policies are JSON documents that define these permissions. They are attached to users, groups, or roles.
- Managed Policies: Created and maintained by AWS or you; they can be attached to multiple users.
- Inline Policies: Embedded directly into a single user, group, or role. These are useful for one-off, highly specific permissions.
Hands-On: Creating an IAM User and Policy
For our running project, let's create a dedicated user for your development machine that has access to read S3 buckets but nothing else.
-
Create the User:
- Log into the AWS Management Console and navigate to the IAM service.
- Select Users -> Create user.
- Name it
dev-userand ensure "Provide user access to the AWS Management Console" is unchecked (since we are using the CLI). - Click through to create the user without attaching any permissions yet.
-
Attach an Inline Policy:
- Click on your new
dev-userin the IAM console. - Select Add permissions -> Create inline policy.
- Switch to the JSON tab and paste the following:
- Click on your new
JSON{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:ListAllMyBuckets", "s3:GetBucketLocation" ], "Resource": "arn:aws:s3:::*" } ] }
- Click Review policy, name it
S3ReadOnlyPolicy, and save. This user can now list buckets but cannot delete or upload files.
Testing with the Policy Simulator
Before you run commands, it is best practice to test your logic using the IAM Policy Simulator.
- Open the Policy Simulator.
- Select your
dev-userfrom the list. - Under Service, select S3.
- Select ListAllMyBuckets.
- Click Run Simulation. You should see an "Allowed" result.
- Now, try selecting DeleteBucket. Click Run Simulation again. It will return "Implicitly Denied," confirming your policy is secure.
Common Pitfalls
- Over-permissioning: It is tempting to attach the
AdministratorAccessmanaged policy to every user. Avoid this. Even for development, start with restricted access to avoid accidental infrastructure deletion. - Hardcoding Credentials: Never save your
access_keyandsecret_keyin your source code. Use the~/.aws/credentialsfile as covered in our previous lesson. - Confusing Users and Roles: Users are for people or long-term identity; Roles are for temporary permissions (e.g., granting a Lambda function access to a database). We will cover roles in a later lesson.
Practice Exercise
Create a second policy for your dev-user that denies them access to iam:* actions. Apply this policy and use the simulator to verify that even if you were to add AdministratorAccess later, this "explicit deny" would take precedence.
FAQ
Q: What happens if I have both an Allow and a Deny policy? A: In AWS, an explicit "Deny" always overrides an "Allow."
Q: Can I share an IAM user between two developers? A: No. Each person should have their own IAM user with individual credentials. This ensures accountability through CloudTrail logs.
Recap
We have moved beyond the root user by creating a dedicated IAM user and applying an inline policy. By using the Policy Simulator, we verified that our dev-user adheres to the principle of least privilege, ensuring our project remains secure as we scale.
Up next: Introduction to Infrastructure as Code — we will learn how to define these users and policies in code rather than clicking through the console.
Work with me

Laravel SaaS MVP & Multi-Tenant App Development
Launch your SaaS MVP on Laravel — multi-tenant, subscription-ready, and built by the engineer behind a platform serving 10,000+ paying users.

Custom WordPress Plugin Development
Custom WordPress & WooCommerce plugins built to standard — by the developer behind a plugin with 5,000+ active installs and a SaaS with 10,000+ users.

