【问题标题】:What is Boto3 Inspector v2 list_findings' nextToken initial value?Boto3 Inspector v2 list_findings 的 nextToken 初始值是多少?
【发布时间】:2022-02-13 14:30:50
【问题描述】:

我正在使用 boto3 Python 列出 Inspector v2 的发现,在循环中使用 list_findings() 方法,根据AWS Boto3 Inspector2 Docs,我必须将此参数的值设置为 null 以便对列表操作的第一个请求,但是在所有这些情况下,变量 next_token 都会出现错误:

  • nextToken = None: botocore.exceptions.ParamValidationError:参数验证失败: 参数 nextToken 的类型无效,值:None,类型:,有效类型:

  • nextToken = 'null': botocore.errorfactory.ValidationException:调用 ListFindings 操作时发生错误 (ValidationException):操作“ListFindings”中的分页令牌异常:有效负载包装架构无效 -24855

  • nextToken = 空字符串:调用 ListFindings 操作时发生错误 (ValidationException):操作“ListFindings”中的分页令牌异常:有效负载(无加密架构版本)

这是我的代码:

import boto3
inspector = boto3.client("inspector2")
next_token = "" # I change the value of this variable 
while True:
    response = inspector.list_findings(
            filterCriteria={
                'findingStatus': [
                    {
                        'comparison': 'EQUALS',
                        'value': 'ACTIVE'
                    },
                ],
                'findingType': [
                    {
                        'comparison': 'EQUALS',
                        'value': 'PACKAGE_VULNERABILITY'
                    },
                ],
            },
        nextToken=next_token
    )
    next_token= response.get("nextToken") 
    
    # Some Code Here 
    
    if next_token == None:
        break

我对第一个请求的 nextToken 的值应该是什么感到困惑?

【问题讨论】:

  • 对于第一个请求,请不要提供nextToken值。
  • @Marcin 我正在尝试根据 AWS Inspector 2 的调查结果生成某种 Slack 通知,但我担心在返回令牌时可能会遗漏一些东西,我想获得初始值下一个令牌。
  • @JohnRotenstein 我该怎么做?你的意思是在循环之前发出请求吗?
  • 通常,您不会在第一次调用时指定nextToken。它可能作为一个空字符串工作——你尝试过吗?

标签: python amazon-web-services security aws-lambda boto3


【解决方案1】:

AWS docs 中所述,使用paginate 会更容易:

# Create a client
inspector = boto3.client("inspector2")

# Create a reusable Paginator
paginator = inspector.get_paginator('list_findings')

# Create a PageIterator from the Paginator
page_iterator = paginator.paginate(filterCriteria={
                'findingStatus': [
                    {
                        'comparison': 'EQUALS',
                        'value': 'ACTIVE'
                    },
                ],
                'findingType': [
                    {
                        'comparison': 'EQUALS',
                        'value': 'PACKAGE_VULNERABILITY'
                    },
                ],
            })

for page in page_iterator:
    print(page)

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2018-03-03
  • 2023-03-29
  • 1970-01-01
  • 1970-01-01
  • 2012-06-29
  • 2011-01-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多