I have the AMIs I want to allow tagged with the "type" tag.
Here's the policy I tried:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:RunInstances",
"ec2:StartInstances"
],
"Condition": {
"StringEquals": {
"ec2:ResourceTag/type": "permitted_amis"
}
},
"Resource": [
"*"
]
},
{
"Effect": "Allow",
"Action": [
"ec2:DescribeInstances",
"ec2:CreateTags"
],
"Resource": [
"*"
]
}
]
}
When I tried to launch an instance from one of those AMIs, I got permission denied.
The problem is that you don't have ec2:RunInstances permissions any more, because you added that permission together with the condition, so it overrides - it will look for an EC2 instance with that tag; seeing that you have only "ec2:DescribeInstances" on Resource:["*"];
Add two separate statements, and specify the exact resources for each:
Example: (taken from http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ExamplePolicies_EC2.html#ex5)