【发布时间】:2016-01-28 08:10:50
【问题描述】:
我正在寻找一个脚本,该脚本可以根据分配给它的 IAM 角色过滤 AWS 实例,然后 获取它的私有 IP 地址。 我最近问了一个类似的问题:filtering ec2 instances by associated IAM role with boto 答案非常有效。 现在,我想在 Windows PowerShell 上做同样的事情。
我知道 PowerShell 不像 boto 那样提供很好的功能,但是我知道有一个适用于 PowerShell 的 AWS 工具包,您可以使用它来获取有关实例的信息。
我已经设置了一个配置文件以在所有会话上运行。
PS > Set-AWSCredentials -AccessKey AKIAIOSFODNN7EXAMPLE -SecretKey wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY -StoreAs TestUser1
PS > Initialize-AWSDefaults -ProfileName TestUser1 -Region ap-southeast-2
这大致是我的代码在 boto 上的样子,它按 IAM 角色过滤实例,然后将其私有 IP 地址存储在一个列表中。
instancelist = conn.get_only_instances(filters={"iam-instance-profile.arn": "arn:aws:iam::123456789012:instance-profile/TestRole"})
aList = list()
for instance in instancelist:
output1 = instance.private_ip_address
aList.append(output1)
在 PowerShell 中执行此操作的等效方法是什么?
【问题讨论】:
标签: powershell amazon-web-services amazon-ec2 aws-powershell