I have Amazon Connect using an AWS Lambda Function to retrieve data from a PHP server. I've read these docs on Using AWS Lambda Functions with Amazon Connect
I have Lambda set up like this:
exports.handler = (event, context, callback) => {
https.get(url, (httpsResult) => {
httpsResult.setEncoding('utf8');
httpsResult.on('data', function gotResult (body) {
console.log("PHP RETURNED= "+body);
callback(null, body);
});
});
};
PHP returns to lambda a test JSON object:
$testArray=array("test"=>"test string value");
echo json_encode($testArray); exit;
Lambda Cloudwatch logs show PHP RETURNED= {"test": "test string value"}
But when body is returned to AWS Connect, it only logs this:
{
"Results": "The Lambda Function Returned An Error.",
"ContactFlowModuleType": "InvokeExternalResource",
...
}
I've tried several ways in Lambda to build the JSON object response to Connect. When incorrect, the only error logged is as above,
The lambda function returned an error
but not what the error is. But there are no errors in lambda, only in connect.
The only way I seem to pass data successfully is when I ignore the PHP data and set Lambda to callback(null, {"test": "test string value"});
So what is going wrong with my passing of the JSON object from PHP through Lambda?