我想做的(继续我之前问的问题: How can I filter AWS Instances by IAM role in powershell and get the private ip address of that instance? )是获取具有特定 IAM 角色的实例的私有(private) IP 地址。我有一个完美运行的代码:
$filter = New-Object Amazon.EC2.Model.Filter -Property @{Name = "iam-instance-profile.arn"; Value = "arn:aws:iam::123456789012:instance-profile/TestRole"}
$ec2 = @(Get-EC2Instance -Filter $filter)
$ec2instances = $ec2.instances
$ipaddress = $ec2instances.privateipaddress
但是,现在我不想在代码中进行过滤,而是想创建一个 IAM 策略,限制用户只能获取有关具有特定 IAM 角色的实例的信息。因此,如果他们尝试 get-ec2instance
(例如),它应该只返回相关实例的信息,而不是帐户中的所有实例。
这是我的 IAM 政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:DescribeInstances"
],
"Effect": "Allow",
"Resource": [
"*"
],
"Condition": {
"ArnEquals": {
"ec2:InstanceProfile": "arn:aws:iam::12356789102:instance-profile/TestRole"
}
}
}
]
}
但是,当我在 Powershell 上运行 get-ec2instance
时,我被告知我无权执行该操作。我认为这可能是因为 get-ec2instance
仅适用于所有实例,但我不确定。
非常感谢您的帮助,谢谢!
最佳答案
到目前为止,您还没有任何选项可以限制 IAM 用户查看特定的 EC2 实例。
仅存在一个 API 调用 ec2-describe-instances,这表明需要拥有所有实例的所有权限或没有权限。
关于powershell - 用于通过关联的 IAM 角色限制实例的 AWS IAM 策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35216910/