3 回答

TA貢獻1877條經驗 獲得超6個贊
這是因為 node.js 異步調用。您的函數在異步調用返回之前完成運行。我修復了一些代碼行。我希望這對你有幫助。
const getApi= async function() {
return await axios.get(url)
}
const getResponse = async function(){
const data= await getApi()
if (data.status ==200){
return data
}
}
exports.handler = async function() {
return await getResponse().then(res => {
const response = {
statusCode: 200,
body: JSON.stringify(res),
}
return response
}).catch(error => console.error(error))
}

TA貢獻1818條經驗 獲得超7個贊
我建議使用console.log()
整個文件進行調試。默認情況下,您應該能夠在 Cloudwatch 中看到對這些控制臺日志的響應:)
在此處閱讀更多信息:
https://docs.aws.amazon.com/lambda/latest/dg/monitoring-functions-logs.html

TA貢獻1802條經驗 獲得超4個贊
我自己最近遇到了這個問題。解決辦法是:
如果您在 AWS 網關中使用 Lambda 作為授權方,則 Lambda 應返回一個包含 principalId、policyDocument 和上下文的 JSON 對象。
上下文是一個映射,您可以在其中添加您自己的自定義變量,例如字符串、數字和布爾值。
JSON 對象的全部內容將返回給網關。查看此文檔:https : //docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-output.html
我還有一篇關于如何通過 Cloudformation YAML 文件配置網關的非常詳細的 Stackoverflow 帖子:AWS API Gateway with Lambda Authorizer
添加回答
舉報