SQS lambda 总是调用 3 次,不知道为什么?在无服务器 aws 上

SQS lambda invokes 3 times always, don't know why? on serverless aws

这是用 node js 编写的队列消费者代码

const consumer = async (event) => {
  console.log(event)
  for (const record of event.Records) {
    const reqBody = JSON.parse(record.body);
    console.log(reqBody);
  }
  return true;
};

这里您观察到 lambda 函数每 2 秒调用一次

constructs:
  jobs:
    type: queue
    worker:
      timeout: 20
      handler: handler.consumer

我正在使用无服务器框架这是无服务器团队的官方回应 -> enter image description here

I assume you are referring to an SQS queue? You would need to delete the message yourself as SQS does not automatically delete messages: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-using-receive-delete-message.html