在AWS Lambda中发出POST https请求,无需等待响应
我正在尝试使用 Node.js 在我的 AWS Lambda 函数中发出 https 请求(对其他 Lambda 的 API 网关调用),但不等待响应,因此当数据已发送到其他 Lambda(并开始运行)时,我的第一个 Lambda 停止运行。
我一直在尝试执行以下代码:
await new Promise((resolve, reject) => {
const options = {
hostname: 'example.com',
path: '/example/action',
method: 'POST'
}
const req = https.request(options);
console.log('Request: ', req);
req.on('error', error => {
reject(error);
});
// Send data
req.write(JSON.stringify(data));
req.end(() => {
// This is where (in theory) request has been made, and no response received
resolve(req);
});
});
由于从未调用解析,因此会导致超时问题。
有什么想法吗?
I am trying to make an https request (API gateway call to other Lambda) in my AWS Lambda function with Node.js, but without waiting for the response, so when the data has already been sent to the other Lambda (and starts running), my first Lambda stops running.
What I've been trying to do is the following code:
await new Promise((resolve, reject) => {
const options = {
hostname: 'example.com',
path: '/example/action',
method: 'POST'
}
const req = https.request(options);
console.log('Request: ', req);
req.on('error', error => {
reject(error);
});
// Send data
req.write(JSON.stringify(data));
req.end(() => {
// This is where (in theory) request has been made, and no response received
resolve(req);
});
});
It results in a timeout issue, due to resolve is never called.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论