通过SQS lambda发送SQS消息。

问题描述 投票:0回答:1

我有一个 SeedIndicatorInformationSQS-dev.fifo 队列(FiFo),连接到一个新的队列。SeedIndicatorInformationSQS-dev-d13dfe0 兰姆达。我想在 SeedIndicatorInformationSQS-dev-d13dfe0 兰姆巴达至 EvaluationConfigSQS-dev 标准队列。但是没有消息被发送接收。而如果我尝试从一个非SQS连接的lambda(通过AppSync)发送,则可以正常工作。

这个 SeedIndicatorInformationSQS-dev-d13dfe0 lambda的权限如下。permissions lambda

我已经检查过了

  • lambda有发送SQS消息的权限(你可以在那里看到).
  • 这个 EvaluationConfigSQS-dev标准队列是正确的配置,因为我已经...。顺利 从另一个lambda(非QS)发送消息给它。
  • SQS的URL是正确的。
  • 控制台中没有显示任何错误。
  • asyncawait的位置正确(我试过带和不带它们)

以下是CloudWatch的日志。SeedIndicatorInformationSQS-dev-d13dfe0lambda试图发送内容。成功发送至正确的URL,JSON解析为字符串,但没有任何内容。

enter image description here

这是CloudWatch的日志。你可以看到: SeedIndicatorInformationSQS-dev-d13dfe0 成功接收到来自另一个 lambda 函数的消息并进行处理,但没有进一步发送消息。

enter image description here

没有报告任何错误。SeedIndicatorInformationSQS-dev-d13dfe0

enter image description here

内无日志 EvaluationConfigSQS-deventer image description here

但是,如果我尝试在一个非QS 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-6da8b90 (lambda that the EvaluationConfigSQS-dev 标准队列触发器)

enter image description here

我是否需要在这里添加特殊的权限?SeedIndicatorInformatioNSQS-dev.fifo 队列?enter image description here

下面是被调度的JS(我用的是mediator模式,而且成功被调度了,你可以在上面的日志 "Dispatching CREATED_INSTITUTION_CLASS "中看到。我还设法打印了URL,并验证了它确实是对应的那个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
  );
}

下面是s sqsDispatchMessage函数。正如你所看到的,有一个捕捉块,只要有错误就会打印给我(而且它是有效的)。但到目前为止,还没有记录到任何错误。

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);
  }
}

有什么想法吗?这是否可能?

amazon-web-services aws-lambda amazon-sqs
1个回答
0
投票

问题出在我的调度器上。

以前是这样的


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);
}
© www.soinside.com 2019 - 2024. All rights reserved.