Jose A
Jose A

Reputation: 11077

Sending an SQS message via an SQS lambda

I have a SeedIndicatorInformationSQS-dev.fifo queue (FiFo) that connects to a SeedIndicatorInformationSQS-dev-d13dfe0 lambda. I'd like to send a message within the SeedIndicatorInformationSQS-dev-d13dfe0 lambda to the EvaluationConfigSQS-dev standard queue. But no messages are being sent/received. Whereas if I try sending it from a non-SQS connected lambda (via AppSync) it works.

The SeedIndicatorInformationSQS-dev-d13dfe0 lambda has the following permissions: permissions lambda

I have checked:

Here's the CloudWatch log for the SeedIndicatorInformationSQS-dev-d13dfe0lambda trying to dispatch the content: Successfully sent to the right URL, JSON parsed to string, but nothing.

enter image description here

Here's the CloudWatch Log: You can see. SeedIndicatorInformationSQS-dev-d13dfe0 successfully receives the message from another lambda function and processes it, but no further messages are sent.

enter image description here

No errors reported within SeedIndicatorInformationSQS-dev-d13dfe0

enter image description here

No logs within EvaluationConfigSQS-dev enter image description here

But, if I try to send it within a non-SQS lambda, it works. enter image description here

Received event: enter image description here

This is the classes-dev-eefa2af lambda that sends successfully to EvaluationConfigSQS-dev (and coincidentally is the one which triggers the SeedIndicatorInfromationSQS-dev.fifo SQS. enter image description here

Here are the permissions for EvaluationConfigSQS-dev-6da8b90 (lambda that the EvaluationConfigSQS-dev standard queue triggers)

enter image description here

By any chance, do I need to add special permissions to the SeedIndicatorInformatioNSQS-dev.fifo queue? enter image description here

Here's the JS that gets dispatched (I'm using a mediator pattern, and it's successfully getting dispatched, you can see it in the logs above "Dispatching CREATED_INSTITUTION_CLASS". I have also managed to print the URL and verified that it's actually the one that corresponds to it.

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

Here's the sqsDispatchMessage function. As you can see, there's a catch block that will print me whenever there's an error (and it works). But so far, no error has been recorded.

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

Any ideas? Is it even possible?

Upvotes: 0

Views: 1932

Answers (1)

Jose A
Jose A

Reputation: 11077

The problem was in my dispatcher:

It used to be like this:


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

I changed it to:

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

Upvotes: 1

Related Questions