WhatsApp消息的Lambda AWS和Twilio出现X秒错误后任务超时(&Q) [英] "Task timed out after X seconds" error with Lambda AWS and Twilio for WhatsApp message
本文介绍了WhatsApp消息的Lambda AWS和Twilio出现X秒错误后任务超时(&Q)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试实现Lambda函数以使用Twilio服务发送WhatsApp消息。
我已经上传了Twilio NPM包(我得到的是&Cannot Fin Twilio模块&,但我添加了层,不再收到错误)。我使用的是Node14,我的压缩NPM包包含NodeJS/NODE_MODULES.结构(不是节点14,但我知道它可以同时使用两者)。也许这就是它不工作的原因?
那之后我就卡住了。我不断收到超时提示。我将默认的3秒更改为5秒,但仍然出现错误。
我遗漏了什么或做错了什么? 这是我的代码:
'use strict';
console.log('Trying to send a WhatsApp message...');
exports.handler = async (event) => {
const accountSid = 'ACa4818d82a4d6----------'; //The hyphens is to hide credentials or phone numbers
const authToken = '7e5d8205968af11----------';
const client = require('twilio')("ACa4818d------", "7e5d8205968af11-------");
//I event passed the parameters like this to troubleshoot
client.messages
.create({
body: 'Hi, there!',
from: 'whatsapp:+14------',
to: 'whatsapp:+1-------'
})
.then(message => console.log(message.sid))
.done();
};
这是Lambda控制台的响应:
Test Event Name
TestCon
Response
{
"errorMessage": "2021-12-05T04:39:26.463Z 74eb5536-7da6-4d96-bf8e-824230c85089 Task timed out after 5.01 seconds"
}
Function Logs
START RequestId: 74eb5536-7da6-4d96-bf8e-824230c85089 Version: $LATEST
2021-12-05T04:39:21.452Z undefined INFO Trying to send a WhatsApp message...
END RequestId: 74eb5536-7da6-4d96-bf8e-824230c85089
REPORT RequestId: 74eb5536-7da6-4d96-bf8e-824230c85089 Duration: 5005.62 ms Billed Duration: 5000 ms Memory Size: 128 MB Max Memory Used: 86 MB Init Duration: 176.11 ms
2021-12-05T04:39:26.463Z 74eb5536-7da6-4d96-bf8e-824230c85089 Task timed out after 5.01 seconds
Request ID
74eb5536-7da6-4d96-bf8e-824230c85089
推荐答案
我通过增加超时时间解决了此问题。
我从5秒更改为1分钟。 看起来一段时间内的第一个请求大约需要15秒。耗时毫秒的请求之后。
这篇关于WhatsApp消息的Lambda AWS和Twilio出现X秒错误后任务超时(&Q)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文