def lambda_handler(event, context):
"idsA=event['items'][0]['ids']"
当我想用Python调用时,包含来自API的aws lambda中的数组ID的JSON对象项, 它返回此错误:
"string indices must be integers"`
我认为问题可能出现在COnfigure测试事件中:
{
"ids": "ids",
"contents": "contents",
"ResultID": "ResultID",
"QueryID": "QueryID",
"nR": "nR",
"items": "ids"
}
或在JSON正文映射模板中的API getaaway中:
{
"items": [
#foreach($elem in $input.params('items').split(','))
{
"ids": "$elem.ids",
"contents": "$elem.contents"
}#if($foreach.hasNext),#end
#end
],
"QueryID": "$input.params('QueryID')",
"nR": "$input.params('nR')"
}
答案 0 :(得分:1)
听起来在你的测试中,事件项应该是JSON对象数组:
{
"ResultID": "ResultID",
"QueryID": "QueryID",
"nR": "nR",
"items": [
{
"ids": [1, 2, 3],
"contents": ["content1", "content2"]
}
]
}
...但我认为这里也可能存在模板映射问题。对API网关的原始请求是什么样的?