Search code examples
amazon-web-servicesaws-lambdaamazon-sqsaws-java-sdk

How to read all the messages from a SQS ,aggregate all those msgs and store them as a single JSON file to S3 bucket, using lambda Java SDK?


I am trying to read all the messages from a SQS ,aggregate all those msgs and store them as a single JSON file to S3 bucket, using lambda Java SDK?

Following Steps are involved in my implementation

  1. Create a Standard SQS and send 500 messages to that SQS

  2. Write a lambda read all the messages from that SQS using while loop(until message count becomes zero)

  3. After reading all the messages from that SQS, now this lambda will have to aggregate all those received messages in to an ArrayList and convert the arraylist as a single JSON file and store this JSON file at a S3 bucket

now i am stuck at step 3, as AWS spans out multiple lambda instances while reading the SQS messages, hence i am unable to aggregate the received messages at one ArrayList, should i use Dynamo DB to aggregate all the messages and create a single JSON file and store in S3 bucket?

Please suggest a solution to resolve this problem

Thanks, Sundar


Solution

  • Set the ReservedConcurrentExecutions attribute in your Lambda function to 1, therefore avoiding multiple instances to spin up.

    enter image description here