I have an AWS lambda function which I can call synchronously and get results back alright with below code
response = lambda_client.invoke(
FunctionName=FUNCTION_NAME,
InvocationType='RequestResponse',
LogType='Tail',
Payload=payload,
Qualifier=$LATEST
)
The response Payload is of type <botocore.response.StreamingBody object at 0x115fb3160>
So I use below code to extract the payload which works fine.
response_body = response['Payload']
response_str = response_body.read().decode('utf-8')
response_dict = eval(response_str)
Now, I need to call my lambda asynchronously, so I change the invocation type with InvocationType='Event'
It gives me a response with payload of the same type as before, botocore.response.StreamingBody object
but I am getting error with this line - response_dict = eval(response_str)
The error message says
response_dict = eval(response_str)
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing
What am I missing? If the response payload is same type as synchronous call, why is this parsing error? Any suggestion?
EDIT
For clarity, I understand that if the InvocationType='Event'
, then we only get the status of the invoke
call, not the lambda function result. In my case though, I need both - launch the lambda async and get the result back when done. How do I do that? Is writing the result back to s3 and periodically checking that the only option?