Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Saving a json/txt file to S3 from Lambda

New member
Joined
Feb 1, 2023
Messages
9
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
 
New member
Joined
Feb 1, 2023
Messages
17
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:

Code:
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'))))
 
Top