Hi guys, I followed this tutorial http://blog.zerosharp.com/the-serverless-framework-and-php/ in order to execute PHP function with AWS Lambda. Seemed to work everything smooth except wehn I tried to run a function using PDO. Below the easy easy code I’m using:
<?php
$result = updateArxivar();
printf(json_encode($result));
function updateArxivar(){
$db_host = "my_host";
$db_name = "my_dbname";
$db_username = getenv("FLY_DATABASE_USER");
$db_password = getenv("FLY_DATABASE_PW");
try{
$conn = new PDO('mysql:host='.$db_host.';dbname='.$db_name, $db_username, $db_password);
}catch(Exception $e){
fwrite(STDERR, "Hi\n");
return 0;
}
return 1;
}
If I run it locally with sls invoke local --function hello it works like a charm. When I deploy it and run with sls invoke --function hello it fails with 255 code.
I also updated the dockerfile file in order to force the PDO installation and enabling but no luck: here the gist of dockerfile https://gist.github.com/Delfins/23aadc9e418c48e88c4a7491641dc0c9
Anyone can help me? Thanks!
Cheers,
Guido