【发布时间】:2016-05-15 00:04:09
【问题描述】:
我想要做的(继续我之前提出的问题:How can I filter AWS Instances by IAM role in powershell and get the private ip address of that instance?)是获取具有特定 IAM 角色的实例的私有 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 仅适用于所有实例,但我不确定。
非常感谢您的帮助,谢谢!
【问题讨论】:
标签: powershell amazon-web-services amazon-iam aws-powershell