0

I have an array, lets say with a length of 9999. Now I want to send a message to SQS with the contents of each object in the array.

Here is how I want to send the messages:

const promises = tokens.map((token) => { const params = { Body: JSON.stringify(data), }; return sqs.sendMessage({ MessageBody: JSON.stringify(params), QueueUrl: 'my-queue-url', }).promise(); }); await Promise.all(promises); 

Now, the problem is that I trigger this function via API Gateway, which times out after 30 seconds. How can I avoid this? Is there a better way to do this?

3
  • 1
    Do you need a synchronous response, or are you okay if you know the system is working on it? Commented Mar 17, 2022 at 15:12
  • 2
    docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/… Commented Mar 17, 2022 at 15:13
  • @Maurice Nope. Don‘t need a response. Just need to trigger it Commented Mar 17, 2022 at 15:19

1 Answer 1

2

Based on your response in the comments I suggest you do two things:

  1. Use the SendMessageBatch API to reduce the number of API calls and speed up the process as @Marc B suggests
  2. Set up asynchronous invocation of the backend Lambda function. This means the API Gateway will just send the Event to your Lambda and not wait for the response. That means the Lambda functions is free to run up to 15 minutes. If you have more messages than can be handled in that period of time, you may want to look into StepFunctions.
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.