Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Saving a json/txt file to S3 from Lambda

I am using lambda to run a program. Once it is run I need to save some data as a json file or txt. I tried to see if there is a way to write a file in lambda and save it but there are no write permissions it is read only. So I am now thinking of saving this json object in S3, so that i can retrieve it later. Is there a way to upload to s3 without writing a file and just upload an object

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

AWS Lambda is just another runtime environment for your Python code. You can utilize the boto3 SDK to upload your file to S3.
Something along the lines of the following should work:

import json

import boto3

s3 = boto3.resource('s3')
obj = s3.Object('BUCKET_NAME', 'FILE_NAME.json')

obj.put(Body=(bytes(json.dumps(data).encode('UTF-8'))))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading