Best practice: Avoid using the Root User. Instead, create IAM Users with minimal permissions needed to manage resources. This makes management easier and reduces security risks.
In this section, we will create a policy to restrict a user to only interact with EC2 Instances in the ap-southeast-1 region.
2.1. On the left navigation menu, select Policies.
2.2. In the Policies interface, click Create policy.
2.3. Step 1 - Specify permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "ec2:*",
"Resource": "*",
"Condition": {
"StringEquals": {
"aws:RequestedRegion": "ap-southeast-1"
}
}
}
]
}
This JSON allows interactions with EC2 resources but only in the ap-southeast-1 region.
2.4. Step 2 - Review and Create:
Provide a name and description for the policy.
Click Create policy.
To reuse the above policy, assign it to an IAM Group. All IAM Users in the group will share the same permissions.
3.1. Access User groups from the left navigation menu.
3.2. In the User groups interface, click Create group.
3.3. In the Create user group interface:
4.1. Access Users from the left navigation menu.
4.2. Click Create user.
4.3. Step 1 - Specify user details:
4.4. Step 2 - Set permissions:
4.5. Step 3 - Review and Create:
4.6. Step 4 - Retrieve password:
4.7. Log in as the IAM User:
Check the EC2 service in us-east-1: The policy should restrict access in this region.
Check the EC2 service in ap-southeast-1: Access should be allowed.