IAM Policy Examples For AWS EC2
IAM Policy Examples For AWS EC2
Introduction
Examples
1. Start/Stop an EC2 Instance
This policy allows the user to start, stop, and terminate EC2 instances:
JSON
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:StartInstances",
"ec2:StopInstances",
"ec2:TerminateInstances"
],
"Resource": "*"
}
]
}
This policy allows the user to start and stop only EC2 instances with a
specific tag key and value:
JSON
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:StartInstances",
"ec2:StopInstances"
],
"Resource": [
"arn:aws:ec2:<region>:<account-
id>:instance/*",
"arn:aws:ec2:<region>:<account-id>:tag/*"
],
"Condition": {
"StringLike": {
"ec2:ResourceTag/key": "Environment",
"ec2:ResourceTag/value": "Development"
}
}
}
]
}
Note:
Replace <region> with your AWS region and <account-id>
with your account ID.
This example uses the StringLike condition to restrict access
based on tag key and value. You can modify the condition to meet
your specific requirements.
Additional Considerations
When creating IAM policies, consider the principle of least privilege
and grant only the minimum permissions necessary for the user or
role to perform its intended function.
Utilize resource-level permissions whenever possible to further
restrict access.
Regularly review and update IAM policies to ensure they remain