IAM 策略不允许我启动实例

IAM 策略不允许我启动实例

我已将以下策略附加给用户,以便他们可以启动和停止一个特定实例。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "ec2:StartInstances",
                "ec2:StopInstances"
            ],
            "Resource": "arn:aws:ec2:::instance/i-01234567890"
        },
        {
            "Sid": "VisualEditor1",
            "Effect": "Allow",
            "Action": "ec2:DescribeInstanceStatus",
            "Resource": "*"
        }
    ]
}

使用以下代码,我在尝试启动该实例时收到 403 错误:

conn = boto.ec2.connect_to_region("eu-west-1",
  aws_access_key_id=AWS_ACCESS,
  aws_secret_access_key=AWS_SECRET)

instance = conn.start_instances(instance_ids=['i-01234567890'], dry_run=True)

我究竟做错了什么?

我在控制台中模拟了该策略,看起来不错,我可以在模拟下启动该特定实例。我尝试将 DescribeInstances (*) 添加到权限中,但即使采用这种方法也不起作用:

>>> conn.get_only_instances()[0]
Instance:i-01234567890
>>> conn.get_only_instances()[0].start()
<Permission Denied>

答案1

"arn:aws:ec2:::instance/i-01234567890"

"arn:aws:ec2:region:account-id:instance/i-01234567890"

您需要替换您的区域和帐户 ID,因为它们是此资源类型所必需的,如以下文档所述https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#arn-syntax-ec2

相关内容