我正在尝试从我们的 VPC 的 Lambda 函数调用 Apigateway 上的 RestApi(不是默认的,默认的工作正常)。它抛出 403 错误,我在 CloudWatch 日志或 Apigateway 日志中找不到任何详细信息。我认为我无法从 Lambda 访问 Apigateway。我尝试使用 Apigateway 资源策略来允许我的 VPC 请求,但没有任何改变。
我尝试了以下事情:
Lambda/Node.js 代码片段:
const { default: axios } = require('axios')
exports.handler = async (event) => {
const res = await axios.get(
'https://XXXX.execute-api.REGION.amazonaws.com/ABC/hello-world/healthcheck',
{"headers": { "x-api-key": "18yXXXXXXXXXaSI0usGYYYYYY" }})
console.log(JSON.stringify(res,null,2))
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
}
return response
}
错误响应
{
"message":"Request failed with status code 403",
"name":"AxiosError",
"config":{
"transitional":{
"silentJSONParsing":true,
"forcedJSONParsing":true,
"clarifyTimeoutError":false
},
"transformRequest":[
null
],
"transformResponse":[
null
],
"timeout":0,
"xsrfCookieName":"XSRF-TOKEN",
"xsrfHeaderName":"X-XSRF-TOKEN",
"maxContentLength":-1,
"maxBodyLength":-1,
"env":{
},
"headers":{
"Accept":"application/json, text/plain, */*",
"x-api-key":"18yXXXXXXXXXaSI0usGYYYYYY",
"User-Agent":"axios/0.27.2"
},
"method":"get",
"url":"https://XXXX.execute-api.REGION.amazonaws.com/ABC/hello-world/healthcheck"
},
"code":"ERR_BAD_REQUEST",
"status":403
}
你能解决这个问题吗?