【发布时间】:2017-11-26 22:06:51
【问题描述】:
我正在尝试更多地了解 Boto3 脚本。
我想在同一个区域的多个 VPC 中搜索未使用的安全组
我正在尝试让 python 脚本在这里工作: boto3 searching unused security groups
所以我的list-unused-sq.py如下所示
import boto3
ec2 = boto3.resource('ec2')
sgs = list(ec2.security_groups.all())
insts = list(ec2.instances.all())
all_sgs = set([sg.group_name for sg in sgs])
all_inst_sgs = set([sg['GroupName'] for inst in insts for sg in inst.security_groups])
unused_sgs = all_sgs - all_inst_sgs
print 'Total SGs:', len(all_sgs)
print 'SGS attached to instances:', len(all_inst_sgs)
print 'Orphaned SGs:', len(unused_sgs)
print 'Unattached SG names:', unused_sgs
当我运行脚本时出现以下错误
./list-unused-sq.py: line 1: import: command not found
./list-unused-sq.py: line 3: syntax error near unexpected token `('
./list-unused-sq.py: line 3: `ec2 = boto3.resource('ec2') #You have to change this line based on how you pass AWS credentials and AWS config'
是否有人能够指出我哪里出了问题以及我需要做些什么来纠正它?
谢谢 尼克
【问题讨论】:
标签: python python-2.7 amazon-web-services