Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.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 Boto3使用NextToken通过路径从SSM获取参数_Python_Boto3_Aws Ssm_Aws Parameter Store - Fatal编程技术网

Python Boto3使用NextToken通过路径从SSM获取参数

Python Boto3使用NextToken通过路径从SSM获取参数,python,boto3,aws-ssm,aws-parameter-store,Python,Boto3,Aws Ssm,Aws Parameter Store,为了从参数存储SSM收集一些值,我已经使用boto3一段时间了,这是我使用的代码,非常简单: def get_raw_parameters_group_by_namespace(namespace_path): raw_params_response = None try: if not namespace_path: raise Exception('Namespace path should be specified to get d

为了从参数存储SSM收集一些值,我已经使用boto3一段时间了,这是我使用的代码,非常简单:

def get_raw_parameters_group_by_namespace(namespace_path):
    raw_params_response = None

    try:
        if not namespace_path:
            raise Exception('Namespace path should be specified to get data')
        raw_params_response = ssm_ps.get_parameters_by_path(Path = namespace_path)
    except Exception as e:
        raise Exception('An error ocurred while trying to get parameters group: ' + str(e))

    return raw_params_response
我以前在SSM中有大约7到10个参数,这种方法工作得很好,但是,这些天我们需要添加一些额外的参数,它们的数量增加到14个,因此我尝试在boto3 SSM方法中添加一个名为“MaxResults”的属性,并将其设置为50:

ssm_ps.get_parameters_by_path(Path = namespace_path, MaxResults = 50)
但我得到了以下信息:

"error": "An error ocurred while trying to get parameters group: An error occurred (ValidationException) when calling the GetParametersByPath operation: 1 validation error detected: Value '50' at 'maxResults' failed to satisfy constraint: Member must have value less than or equal to 10."
与团队讨论后,增加帐户中的配额不是一个选项,因此我想知道使用
“NextToken”
属性是否是一个好选项

我不知道如何使用它,我已经搜索了一些例子,但我找不到有用的东西。请问有人知道如何使用NextToken吗?或者一个关于它应该如何工作的例子

我试过这样的方法:

raw_params_response = ssm_ps.get_parameters_by_path(Path = namespace_path, NextToken = 'Token')
但是我不确定这个的用法


提前谢谢。

我记得在某个时候遇到过这个问题

您要使用分页器-

我就是这样使用它的:

import boto3

client = boto3.client('ssm',region_name='eu-central-1')

paginator = client.get_paginator('get_parameters_by_path')

response_iterator = paginator.paginate(
    Path='/some/path'
)

parameters=[]

for page in response_iterator:
    for entry in page['Parameters']:
        parameters.append(entry)
您将在参数中获得一个类似于
[{“Name”:/some/path/param,“Value”:“something”}]
的列表,其中包含路径下的所有参数

*编辑:响应将比名称、值键更丰富。请查看paginator文档