def lambda_handler(event, context):
"idsA=event['items'][0]['ids']"
當我想與Python調用包含陣列ID的JSON對象的項目。在AWS的λ,從API, 它返回此錯誤:字符串的索引必須是整數AWS API拉姆達
"string indices must be integers"`
我覺得這個問題可以在配置測試賽:
{
"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')"
}
假設你的文章中的第一個詞典被稱爲'event',那麼'event ['items'] [0]'返回鍵'items'的值的第一個字母,這是你試圖切片的一個字符串使用另一個'string'。如果我誤解了,請發佈'event'看起來像什麼。 –
檢查我的更新 – user2165656
對不起,仍然沒有幫助我理解。正如我之前提到的那樣,問題在於你正在用另一個字符串索引一個字符串。它必須意味着'event ['items'] [0]'是一個字符串,而不是你所假設的字典。 –