Downloading images form AWS S3 via Lambda and API Gateway
ฝัง
- เผยแพร่เมื่อ 1 ส.ค. 2024
- Prerequisite:
---------------------
Serverless File Uploader with AWS HTTP Gateway and S3 - Step by Step Tutorial
• Serverless File Upload...
Code:
---------
import json
import boto3
import base64
client=boto3.client('s3')
def lambda_handler(event, context):
TODO implement
print(event)
bucket_name=event['queryStringParameters']['bucketname']
image_file_name=event['queryStringParameters']['image']
print("Bucket Name: ",bucket_name)
print("Image file name: ",image_file_name)
response = client.get_object(
Bucket=bucket_name,
Key=image_file_name,
)
print("Response from s3 : ",response)
image_file_to_be_downloaded=response['Body'].read()
return {
'statusCode': 200,
'body':base64.b64encode(image_file_to_be_downloaded) ,
'isBase64Encoded': True
}
Check this playlist for more AWS Projects in Big Data domain:
• Demystifying Data Engi... - วิทยาศาสตร์และเทคโนโลยี
Hi, how to delete the version enabled S3 bucket via Lambda and API Gateway
sir what if I get "Unable to marshal response"
Hi, same example dowmload PDF?
How to upload file to S3 via lambda and apigateway. ?
Hello TAPENDRA KUMAR, you can refer the below videos --
Approach 1:
----------------------
Serverless File Uploader with AWS HTTP Gateway and S3 - Step by Step Tutorial
th-cam.com/video/13SswprYsHQ/w-d-xo.html
Approach 2:
----------------------
Use Pre-signed URL's to Upload files to Amazon S3
th-cam.com/video/co4iQUgT2ZY/w-d-xo.html
Hope this will be helpful! Happy Learning :-)
exact same code for a png file -> error: json not serializable