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

Can't receive response from Aws Lambda after It's triggered by S3

So I use API Gateway to post an image to an S3 bucket and that triggers a Lambda function which gets the image converts it and returns the binary data. But the problem is that I don’t see that return on front end so I can’t get that image.
This is my lambda function.

def lambda_handler(event, context):
    # print(context)
    bucket = event['Records'][0]['s3']['bucket']['name']
    key = urllib.parse.unquote_plus(event['Records'][0]['s3']['object']['key'], encoding='utf-8')
    converted_image = paste_logo("https://" + bucket + ".s3.eu-west-3.amazonaws.com/" + key)

    return {'isBase64Encoded'   : True,
        'statusCode'        : 200,
        'headers'           : { 'Content-Type': "application/json" },
        'body'              : json.loads(json.dumps(converted_image, default=str)) }

This is what I see in front end
enter image description here

I also posted the image to S3 with postman and all i get is status 200 ok

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

>Solution :

S3 invokes Lambda asynchronously. S3 will return a response from the object upload before it even invokes the Lambda function. There is no way to change this behavior.

If you want your API to return the response of the Lambda function, then your API needs to invoke the Lambda function directly.

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