I have a simple AWS Lambda function created using Python. I have created an HTTP Endpoint URL to call the function which requires no authentication. I get a proper response if I call the HTTP Endpoint URL using Request library in Python. But I am trying to create a Microsoft Power Automate flow that can invoke the Lambda function using its HTTP Endpoint URL.
The lambda_handler simply returns the following:
return {
'statusCode': 200,
'body': 'Hello World from AWS'
}
When I run an HTTP Flow with a GET request to lambda function url, I get an error message as below:
Http request failed: the content was not a valid JSON. Error while parsing JSON: 'Unexpected character encountered while parsing value: H. Path '', line 0, position 0.'
I have attached an image of the flow configuration.
CodePudding user response:
You have to return a valid JSON from your Lambda.
'Hello World from AWS'
is just a string, and the error tells you that H
is an unexpected JSON symbol.
You have to wrap your response into json.dumps
function:
Change your code to:
import json
return {
'statusCode': 200,
'body': json.dumps('Hello World from AWS')
}