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...
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 6

  • @prasadk5866
    @prasadk5866 ปีที่แล้ว

    Hi, how to delete the version enabled S3 bucket via Lambda and API Gateway

  • @user-dg9yc9hf6j
    @user-dg9yc9hf6j 2 ปีที่แล้ว

    sir what if I get "Unable to marshal response"

  • @MiguelCamachomiguecam
    @MiguelCamachomiguecam 10 หลายเดือนก่อน

    Hi, same example dowmload PDF?

  • @tapendrakumar2776
    @tapendrakumar2776 2 ปีที่แล้ว +1

    How to upload file to S3 via lambda and apigateway. ?

    • @KnowledgeAmplifier1
      @KnowledgeAmplifier1  2 ปีที่แล้ว

      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 :-)

  • @justinskidmore9677
    @justinskidmore9677 2 ปีที่แล้ว

    exact same code for a png file -> error: json not serializable