AWS Identity and Access Management
User Guide

EC2: Start or Stop Instances Based on Matching Principal and Resource Tags

This example shows how you might create a policy that allows a principal to start or stop an Amazon EC2 instance when the instance's resource tag and the principal's tag have the same value for the tag key CostCenter. This policy grants the permissions necessary to complete this action from the AWS API or AWS CLI only. To use this policy, replace the red italicized text in the example policy with your own information.

Note

As a best practice, attach policies with the aws:PrincipalTag condition key to IAM groups, for the case where some users might have the specified tag and some might not.

{ "Version": "2012-10-17", "Statement": { "Effect": "Allow", "Action": [ "ec2:startInstances", "ec2:stopInstances" ], "Resource": "*", "Condition": {"StringEquals": {"ec2:ResourceTag/CostCenter": "${aws:PrincipalTag/CostCenter}"}} } }