๐Ÿ” Mastering AWS IAM: How to Control EC2 Access Like a Pro [Part-5]

Ever wondered how tech companies ensure their interns can’t accidentally shut down production servers? The answer lies in AWS IAMโ€”and today, you’ll master it.

๐Ÿšจ The Problem Every Developer Faces

Picture this: You’re scaling your applicat…


This content originally appeared on DEV Community and was authored by Suvrajeet Banerjee

Ever wondered how tech companies ensure their interns can't accidentally shut down production servers? The answer lies in AWS IAMโ€”and today, you'll master it.

๐Ÿšจ The Problem Every Developer Faces

Picture this: You're scaling your application for the holiday season rush. Traffic is about to spike 10x, and you need additional EC2 instances running. But here's the catchโ€”you're also onboarding a new team member who needs access to test environments without touching production.

One wrong click, and your live application could go dark.

Sound familiar? Welcome to the world of cloud security, where AWS Identity and Access Management (IAM) becomes your best friend.

๐ŸŽฏ What You'll Build Today

By the end of this tutorial, you'll have:

โœ… Two EC2 instances - one for production, one for development

โœ… A bulletproof IAM policy that restricts access based on environment tags

โœ… A dedicated IAM user with limited permissions

โœ… Hands-on testing to verify everything works as expected

๐Ÿš€ Step 1: Launch Your EC2 Instances

First, let's create the infrastructure we'll be securing. We'll launch two instances with different environment tags.

Creating the Production Instance

  1. Navigate to EC2 Console

    • Open your AWS Management Console
    • Search for "EC2" in the services search bar
    • Switch to your preferred region
  2. Launch Your First Instance

    • Click "Launch instance"
    • Configure the following:
   Name: web-server-prod
  1. Add Environment Tags

    • Click "Add additional tags"
    • Create a new tag:
      • Key: Env
      • Value: production
  2. Configure Basic Settings

    • Choose a Free tier eligible AMI (Amazon Machine Image)
    • Select a Free tier eligible instance type
    • For Key pair: Select "Proceed without a key pair"
  3. Launch the Instance

Creating the Development Instance

Repeat the same process with these modifications:

Name: web-server-dev
Tag Key: Env
Tag Value: development

๐ŸŽ‰ Checkpoint: You now have two instances with different environment tags!

๐Ÿ›ก๏ธ Step 2: Create a Bulletproof IAM Policy

Now comes the magicโ€”creating a policy that allows access to development resources while blocking production access.

Understanding the Policy Structure

Navigate to IAM โ†’ Policies โ†’ Create policy, then switch to JSON editor and paste this policy:

{    
  "Version": "2012-10-17",    
  "Statement": [        
    {            
      "Effect": "Allow",            
      "Action": "ec2:*",            
      "Resource": "*",            
      "Condition": {                
        "StringEquals": {                    
          "ec2:ResourceTag/Env": "development"                
        }            
      }        
    },        
    {            
      "Effect": "Allow",            
      "Action": "ec2:Describe*",            
      "Resource": "*"        
    },        
    {            
      "Effect": "Deny",            
      "Action": [                
        "ec2:DeleteTags",                
        "ec2:CreateTags"            
      ],            
      "Resource": "*"        
    }    
  ] 
}

๐Ÿ” Policy Breakdown

Statement 1: Allows all EC2 actions, but only on resources tagged with Env: development

Statement 2: Allows describing all EC2 resources (needed for console navigation)

Statement 3: Denies tag modification to prevent privilege escalation

Policy Details:

  • Name: DevEnvironmentPolicy
  • Description: IAM Policy for development environment access

๐Ÿ‘ฅ Step 3: Set Up User Groups and Users

Create the User Group

  1. Navigate to IAM โ†’ User groups โ†’ Create group
  2. Configure Group:
    • Name: dev-team-group
    • Attach policies: Select DevEnvironmentPolicy

Create the IAM User

  1. Navigate to IAM โ†’ Users โ†’ Create user
  2. User Configuration:
   Username: dev-team-member
   โ˜‘๏ธ Provide user access to AWS Management Console
   โ˜ Users must create new password at next sign-in
  1. Add to Group: Select dev-team-group

๐Ÿ’ก Pro Tip: In production, always require password changes on first login!

๐Ÿ”ง Step 4: Create an Account Alias

Make login easier for your team by creating a friendly account alias.

  1. Navigate to IAM โ†’ Dashboard
  2. Create Account Alias:
   Alias: your-company-aws-dev

This changes your sign-in URL from:

https://123456789.signin.aws.amazon.com/console/

To:

https://your-company-aws-dev.signin.aws.amazon.com/console/

๐Ÿงช Step 5: Test Your Security Configuration

Time to verify everything works as expected!

Testing as the IAM User

  1. Open an incognito window
  2. Navigate to your custom sign-in URL
  3. Log in with your IAM user credentials

Security Test 1: Try to Stop Production Instance

  1. Navigate to EC2 โ†’ Instances
  2. Select your production instance
  3. Actions โ†’ Instance state โ†’ Stop

Expected Result: โŒ Access denied error

Security Test 2: Try to Stop Development Instance

  1. Select your development instance
  2. Actions โ†’ Instance state โ†’ Stop

Expected Result: โœ… Instance stops successfully

๐ŸŽฏ Advanced: Using IAM Policy Simulator

For faster permission testing, use the IAM Policy Simulator:

  1. Navigate to IAM โ†’ Policy Simulator
  2. Select your user: dev-team-member
  3. Test actions: Try ec2:StopInstances on both instances
  4. View results: See permissions without actually performing actions

๐Ÿงน Step 6: Clean Up Resources

Always clean up to avoid charges:

Delete EC2 Instances

  1. Terminate both production and development instances

Delete IAM Resources

  1. Remove user from group
  2. Delete the IAM user
  3. Delete the user group
  4. Delete the custom policy
  5. Remove account alias

๐ŸŽ‰ What You've Accomplished

You've just built a production-ready security system that:

๐Ÿ”’ Restricts access based on environment tags

๐Ÿท๏ธ Uses resource tagging for granular control

๐Ÿ‘ฅ Implements group-based permissions for scalability

๐Ÿงช Includes testing strategies for verification

๐Ÿš€ Next Steps

Ready to level up your AWS security game?

๐Ÿ” Explore cross-account access with IAM roles

๐Ÿ“Š Implement CloudTrail for audit logging

๐Ÿ›ก๏ธ Set up MFA for additional security layers

๐ŸŽฏ Learn about service-linked roles for AWS services

๐Ÿ’ก Key Takeaways

AWS IAM isn't just about restricting accessโ€”it's about enabling teams to work efficiently while maintaining security. The combination of resource tags, conditional policies, and user groups creates a powerful, scalable security model.

Remember: Security is not a feature you add laterโ€”it's a foundation you build upon.

Found this tutorial helpful? Drop a comment below and share your IAM security wins! ๐Ÿš€


This content originally appeared on DEV Community and was authored by Suvrajeet Banerjee


Print Share Comment Cite Upload Translate Updates
APA

Suvrajeet Banerjee | Sciencx (2025-07-14T17:25:58+00:00) ๐Ÿ” Mastering AWS IAM: How to Control EC2 Access Like a Pro [Part-5]. Retrieved from https://www.scien.cx/2025/07/14/%f0%9f%94%90-mastering-aws-iam-how-to-control-ec2-access-like-a-pro-part-5/

MLA
" » ๐Ÿ” Mastering AWS IAM: How to Control EC2 Access Like a Pro [Part-5]." Suvrajeet Banerjee | Sciencx - Monday July 14, 2025, https://www.scien.cx/2025/07/14/%f0%9f%94%90-mastering-aws-iam-how-to-control-ec2-access-like-a-pro-part-5/
HARVARD
Suvrajeet Banerjee | Sciencx Monday July 14, 2025 » ๐Ÿ” Mastering AWS IAM: How to Control EC2 Access Like a Pro [Part-5]., viewed ,<https://www.scien.cx/2025/07/14/%f0%9f%94%90-mastering-aws-iam-how-to-control-ec2-access-like-a-pro-part-5/>
VANCOUVER
Suvrajeet Banerjee | Sciencx - » ๐Ÿ” Mastering AWS IAM: How to Control EC2 Access Like a Pro [Part-5]. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/07/14/%f0%9f%94%90-mastering-aws-iam-how-to-control-ec2-access-like-a-pro-part-5/
CHICAGO
" » ๐Ÿ” Mastering AWS IAM: How to Control EC2 Access Like a Pro [Part-5]." Suvrajeet Banerjee | Sciencx - Accessed . https://www.scien.cx/2025/07/14/%f0%9f%94%90-mastering-aws-iam-how-to-control-ec2-access-like-a-pro-part-5/
IEEE
" » ๐Ÿ” Mastering AWS IAM: How to Control EC2 Access Like a Pro [Part-5]." Suvrajeet Banerjee | Sciencx [Online]. Available: https://www.scien.cx/2025/07/14/%f0%9f%94%90-mastering-aws-iam-how-to-control-ec2-access-like-a-pro-part-5/. [Accessed: ]
rf:citation
» ๐Ÿ” Mastering AWS IAM: How to Control EC2 Access Like a Pro [Part-5] | Suvrajeet Banerjee | Sciencx | https://www.scien.cx/2025/07/14/%f0%9f%94%90-mastering-aws-iam-how-to-control-ec2-access-like-a-pro-part-5/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.