Home > other >  Better way to save AWS Lambda response to S3
Better way to save AWS Lambda response to S3

Time:09-23

I have a lambda handler returning response and I want to save the response as a JSON file to S3.

I went through some pages describing how to save information from AWS lambda to S3 using boto3 directly called from the lambda function. However, I'd like the lambda function to concentrate on calculating and making a response then let another lambda or module for creating such output on S3.

Is there any way offered by AWS? I guess the StepFunctions is a way to go but I'd like to know if there is another better way.

CodePudding user response:

If you don't want to do it from the same lambda wit boto3 you have quite a few options. As you mentioned on your own, one option could be another lambda, for which you'll need a trigger, which on it's own could be:

  1. Calling the second lambda from the first lambda directly with boto3
  2. Sending the response to SNS which will trigger the second lambda which will then parse and save it to S3.
  3. Sending the response as a message to SQS which will be then processed by the second lambda.
  4. Sending it as an event to AWS EventBridge which will trigger the second lambda similar to the above.
  5. As suggested by yourself and other answers/comments - Step Functions.

In general, it depends on your use case I'm not quite sure what your payload is, but the best option could actually be to push it directly from your first lambda either way.

  • Related