EC2: Start or stop instances based on tags - Amazon Identity and Access Management
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

EC2: Start or stop instances based on tags

This example shows how you might create an identity-based policy that allows starting or stopping instances with the tag key–value pair Project = DataAnalytics, but only by principals with the tag key–value pair Department = Data. This policy grants the permissions necessary to complete this action programmatically from the Amazon API or Amazon CLI. To use this policy, replace the italicized placeholder text in the example policy with your own information. Then, follow the directions in create a policy or edit a policy.

The condition in the policy returns true if both parts of the condition are true. The instance must have the Project=DataAnalytics tag. In addition, the IAM principal (user or role) making the request must have the Department=Data tag.

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": [ { "Sid": "StartStopIfTags", "Effect": "Allow", "Action": [ "ec2:StartInstances", "ec2:StopInstances" ], "Resource": "arn:aws:ec2:region:account-id:instance/*", "Condition": { "StringEquals": { "aws:ResourceTag/Project": "DataAnalytics", "aws:PrincipalTag/Department": "Data" } } } ] }