我尝试获取在我的aws帐户中创建的API密钥列表。有50个Api键。我想为每个请求列出10个Api密钥。这是代码段。
import boto3
client = boto3.client('apigateway')
response = client.get_api_keys(
limit=10,
position="1",
)
print response
当我运行脚本时,它显示错误,
Traceback (most recent call last):
File "test.py", line 7, in <module>
position="1",
File "C:\Users\Murthy\workspace\my_project\venv\lib\site-packages\botocore\client.py", line 310, in _api_call
return self._make_api_call(operation_name, kwargs)
File "C:\Users\Murthy\workspace\my_project\venv\lib\site-packages\botocore\client.py", line 599, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.BadRequestException: An error occurred (BadRequestException) when calling the GetApiKeys operation: Invalid position parameter
我做错了吗?
每个查询的最大结果数也是500.我们如何知道执行分页的结果总数?
答案 0 :(得分:-1)
position变量充当令牌。它用于获取请求的下一页。 在第一次检索使用计划的调用中,应将职位设置为null,然后要获取下一页,您必须在上一个响应中为该职位分配该职位的值。 position变量更像是令牌。
import boto3
client = boto3.client('apigateway')
response = client.get_api_keys(
limit=10,
position=null,
)
print response
您的回复将是这样
{
"position": "vWQ3Uzc4bAY2YQ%3D%3D",
"items": [
{
"id": "fqewi1",
"name": "3rd Party",
"description": null,
"apiStages": [],
"throttle": {
"burstLimit": 2,
"rateLimit": 1.0
},
.
.
.
}
您的下一个请求将采用这种格式
import boto3
client = boto3.client('apigateway')
response = client.get_api_keys(
limit=10,
position="vWQ3Uzc4bAY2YQ%3D%3D",
)
print response
这将返回下一页。对于最后一页,该位置将为空。