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

Time:06-26

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

CodePudding user response:

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.

  • Related