How To Read AWS S3 File Using Lambda Function (4 Min)
Little Cloud Academy Little Cloud Academy
25 subscribers
404 views
0

 Published On Mar 23, 2024

I'll show you how you can create a Lambda function that can read the content of any file stored in s3. Fully working Hands-om Demo
Lambda function code:
-------------------------------------------------------------
import json
import boto3

s3_client = boto3.client('s3')

def lambda_handler(event, context):
bucket_name = 'myawsbucket1098'
file_name = 'sample.txt'

s3_response = s3_client.get_object(Bucket=bucket_name, Key=file_name)
print("s3_response:", s3_response)

file_data = s3_response["Body"].read().decode('utf')
print("file_data:", file_data)

show more

Share/Embed