通过SQS lambda发送SQS消息

时间:2020-06-12 15:38:09

标签: amazon-web-services aws-lambda amazon-sqs

我有一个SeedIndicatorInformationSQS-dev.fifo队列(FiFo),它连接到一个SeedIndicatorInformationSQS-dev-d13dfe0 lambda。我想在SeedIndicatorInformationSQS-dev-d13dfe0 lambda内向EvaluationConfigSQS-dev标准队列发送一条消息。但是没有消息正在发送/接收。而如果我尝试从非SQS连接的lambda(通过AppSync)发送邮件,则可以正常工作。

SeedIndicatorInformationSQS-dev-d13dfe0 lambda具有以下权限: permissions lambda

我已检查:

  • 该lambda有权发送SQS消息(您可以在此处看到它)。
  • 已正确配置EvaluationConfigSQS-dev标准队列,因为我已成功从另一个lambda(非SQS)向其发送了消息。
  • 该SQS URL是正确的。
  • 控制台中未显示任何错误。
  • 正确放置了异步/等待(我尝试过使用和不使用它们)

这是SeedIndicatorInformationSQS-dev-d13dfe0 lambda试图分发内容的CloudWatch日志:成功发送到正确的URL,JSON解析为字符串,但没有任何响应。

enter image description here

这是CloudWatch日志:您可以看到。 SeedIndicatorInformationSQS-dev-d13dfe0已成功从另一个lambda函数接收消息并对其进行处理,但没有其他消息发送。

enter image description here

SeedIndicatorInformationSQS-dev-d13dfe0内未报告任何错误

enter image description here

EvaluationConfigSQS-dev中没有日志 enter image description here

但是,如果我尝试在非SQS lambda中发送它,则它可以工作。 enter image description here

收到的事件: enter image description here

这是classes-dev-eefa2af lambda,它已成功发送到EvaluationConfigSQS-dev(并且恰巧是触发SeedIndicatorInfromationSQS-dev.fifo SQS的那个)。 enter image description here

以下是EvaluationConfigSQS-dev-6da8b90EvaluationConfigSQS-dev标准队列触发的lambda)的权限

enter image description here

是否有机会向SeedIndicatorInformatioNSQS-dev.fifo队列添加特殊权限? enter image description here

这是要分发的JS(我正在使用中介模式,并且已成功分发,您可以在“ Dispatching CREATED_INSTITUTION_CLASS”上方的日志中看到它。我还设法打印了URL并验证了它的实际作用对应的那个。

export async function institutionClassCreatedEventHandler(
  evt: InstitutionClassCreatedEvent
) {
  const json = JSON.stringify({
    ...evt,
    type: "CLASS_CREATED",
  });


  sqsDispatchMessage(
    "InstitutionClassCreatedEvent",
    evt.tenantId + evt.subject.id,
    json,
    Config.SQS.evaluationConfigSQS.url,
    false
  );
}

这是sqsDispatchMessage函数。如您所见,有一个catch块会在出现错误时将我打印出来(并且有效)。但到目前为止,尚未记录任何错误。

export async function sqsDispatchMessage(
  eventName: string,
  uniqueId: string,
  jsonObjStringifiedToSend: string,
  sqsURL: string,
  isFifoQueue: boolean = true
) {
  try {
    await sqs
      .sendMessage({
        MessageAttributes: {
          EventName: {
            DataType: "String",
            StringValue: eventName,
          },
        },
        ...(isFifoQueue && { MessageGroupId: eventName }),
        MessageBody: jsonObjStringifiedToSend,
        QueueUrl: sqsURL,
        ...(isFifoQueue && { MessageDeduplicationId: uniqueId }),
      })
      .promise();
  } catch (e) {
    console.error(`Error While Sending the ${eventName}`);
    console.error(e.message);
    console.log(jsonObjStringifiedToSend);
  }
}

有什么想法吗?可能吗

1 个答案:

答案 0 :(得分:1)

问题出在我的调度员中

以前是这样的:


export async function dispatchOfEvents({
  type,
  evtArgs,
}: MediatorEvents): Promise<void> {
  logTime(type);
  (events as any)[type].forEach((evt: Function) => {
    evt(evtArgs);
  });
}

我将其更改为:

export async function dispatchOfEvents({
  type,
  evtArgs,
}: MediatorEvents): Promise<void> {
  logTime(type);
  const evts: Promise<any>[] = [];
  for (const evt of (events as any)[type]) {
    evts.push(evt(evtArgs));
  }
  await Promise.all(evts);
}