Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 按SG名称描述ELB AWS安全组规则_Python_Amazon Web Services_Boto3 - Fatal编程技术网

Python 按SG名称描述ELB AWS安全组规则

Python 按SG名称描述ELB AWS安全组规则,python,amazon-web-services,boto3,Python,Amazon Web Services,Boto3,我试图使用Python boto3来描述ELB SecurityGroup并列出它的所有规则 但是,有一个错误说我没有使用默认VPC 我尝试筛选并指定非默认VPC VPC-67890,但没有帮助: client = boto3.client('ec2') response = client.describe_security_groups( ...: Filters = [ ...: { ...: 'Name': 'vpc-id', ...: 'Value

我试图使用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资源,但问题是相同的,它不会返回所有SecurityGroup,只是返回空响应:

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,但问题是Descripte_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'
有人有同样的问题吗


提前感谢。

是的,您不能在默认VPC之外使用GroupName参数。API文档中有点隐藏了它:它说:

[仅限EC2经典和默认专有网络]

您需要将“按组查询”部分保留为空,而是在筛选器中使用组,如下所示:

filters = [dict(Name='group-name', Values=['SG_NAME']), 
           dict(Name='vpc-id', Values=['vpc-67890'])]
client.describe_security_groups(Filters=filters)

是的,您不能在默认VPC之外使用GroupName参数。API文档中有点隐藏了它:它说:

[仅限EC2经典和默认专有网络]

您需要将“按组查询”部分保留为空,而是在筛选器中使用组,如下所示:

filters = [dict(Name='group-name', Values=['SG_NAME']), 
           dict(Name='vpc-id', Values=['vpc-67890'])]
client.describe_security_groups(Filters=filters)