【发布时间】:2018-03-23 20:59:57
【问题描述】:
我正在尝试使用 Python boto3 来描述 ELB SecurityGroup 并列出它的所有规则。
但是,有一个错误提示我没有使用默认 VPC。
我尝试过滤并指定非默认 VPC vpc-67890,但没有帮助:
client = boto3.client('ec2')
response = client.describe_security_groups(
...: Filters = [
...: {
...: 'Name': 'vpc-id',
...: 'Values': [
...: 'vpc-67890']},
...: ],
...: GroupNames=['SG_NAME'])
ClientError: An error occurred (InvalidGroup.NotFound) when calling the DescribeSecurityGroups operation: The security group 'SG_NAME' does not exist in default VPC 'vpc-12345'
我尝试使用 boto3 资源,但它是同样的问题,它不返回所有 SecurityGroups,只是空响应:
ec2 = boto3.resource('ec2')
vpc = ec2.Vpc('vpc-67890')
all_security_groups = vpc.security_groups.all()
specific_security_group = vpc.security_groups.filter(GroupNames=['SG_NAME'])
for i in all_security_groups:
print i
(没有回应)
当我查询我过滤的特定组时,它会引发错误:
for i in specific_security_group:
print i
ClientError: An error occurred (InvalidGroup.NotFound) when calling the DescribeSecurityGroups operation: The security group 'SG_NAME' does not exist in default VPC 'vpc-12345'
我知道如果使用非默认 VPC,它需要 GroupID 而不是 GroupName,但问题是 describe_elb API 仅返回 GroupName。
尝试通过 AWS Cli 描述 SecurityGroup 时也会发生同样的情况:
$ aws ec2 describe-security-groups --group-names SG_NAME
An error occurred (InvalidGroup.NotFound) when calling the DescribeSecurityGroups operation: The security group 'SG_NAME' does not exist in default VPC 'vpc-12345'
有人遇到同样的问题吗?
提前致谢。
【问题讨论】:
标签: python amazon-web-services boto3