how to get return response from AWS Lambda function

后端 未结 2 1015
陌清茗
陌清茗 2020-12-13 00:16

I have a simple lambda function that returns a dict response and another lambda function invokes that function and prints the response.

lambda function A

相关标签:
2条回答
  • 2020-12-13 01:10

    A 202 response means Accepted. It is a successful response but is telling you that the action you have requested has been initiated but has not yet completed. The reason you are getting a 202 is because you invoked the Lambda function asynchronously. Your InvocationType parameter is set to Event. If you want to make a synchronous call, change this to RequestResponse.

    Once you do that, you can get the returned data like this:

    data = invoke_response['Payload'].read()
    
    0 讨论(0)
  • 2020-12-13 01:11

    try: data = invoke_response['Payload'].read() read() because it is a StreamingBody object

    <botocore.response.StreamingBody object at 0x110b91c50>
    

    It is in the boto3 docs. You can find more details about this here: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/resources.html#actions

    0 讨论(0)
提交回复
热议问题