我打算用request调用aws lambda函数中的第三方api。但它显示超时错误。我将lambda函数的时间设置为30s,当我使用postman调用该api时,它会在5秒内发送响应(Error)。我认为请求或axios无法将请求发送到外部api或无法接收响应。有谁可以帮我?我的代码:
request.post({url:url2, json:true, body:body, headers: {
'ACCESS_TIMESTAMP': timestamp,
'Content-Type': 'application/json'
} }, (error, response, body) => {
console.log("------------------I am here----------------------")
callback(null, error)
})当我使用axios时,代码如下所示:
let jsonbody = JSON.stringify(body)
axios.post(url2, jsonbody, {headers: {
'ACCESS_TIMESTAMP': timestamp,
'Content-Type': 'application/json'
}})
.then(res => {
callback(null, res.data)
})
.catch(err => {
callback(null, err)
})我想得到res或err的结果,但它们不执行操作。
发布于 2020-08-01 11:26:48
当您将Lambda定位到私有网络中时,您需要将NAT网关设置到私有子网中。如果您没有接入NAT,Lambda将无法连接到公网,只能与内网IP通信。
https://stackoverflow.com/questions/63200914
复制相似问题