1)如何從博託落實到boto3這個代碼:寶途至Boto3函數實現
conn = boto.connect_ec2() # boto way
sgs = conn.get_all_security_groups() # boto way
for sg in sgs:
if len(sg.instances()) == 0:
print(sg.name, sg.id, len(sg.instances()))
上面的代碼基本上打印所有安全組,沒有附加的情況。
2)以及使用duct.sh()
模塊此個體命令:
command = 'aws ec2 describe-instances --filters "Name=instance.group-id,Values=' + sg.id + '\" --query \'Reservations[*].Instances[*].[InstanceId,Tags[?Key==`Name`] | [0].Value]\' --output json'
聽起來很像'給我寫代碼',所以建議您閱讀boto 3 doc (http://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Client.describe_security_groups)並檢查http://boto3.readthedocs.io/en/latest/reference/services /ec2.html#EC2.Client.describe_instances –
你在問題的第二部分實際提出了什麼?隨意創建一個單獨的問題,如果它是不相關的。 –