Skip to content
Advertisement

Getting null for lambda asyncinvoke function in php

I am trying to call an async lamda function inside of my Php file. But here i am getting null as output.I am not sure about the structure of my below code for calling a async lamda function.

<?php

/**
 * [getMOOCCouponListDetails description].
 *
 * @param [type] $data          [description]
 * @param [type] $vendorDetails [description]
 *
 * @return [type] [description]
 */

require_once 'vendor/autoload.php';
use AwsLambdaLambdaClient;
function addRewardsPoints($vendorid, $data)
{

    if(empty($data) || empty($vendorid)){
        HTTPFailWithCode(401,VBOXLITE_HTTP_MISSING_PARAMS);
    }  
    $Payload = [
        "subscriberid" => isset($data['subscriberid']) ? $data['subscriberid']:" ",
        "videocompletion" =>  isset($data['videocompletion']) ? $data['videocompletion']:" ",
        "profileid" =>  isset($data['profileid']) ? $data['profileid']:" ",  
        "contentid" =>  isset($data['contentid']) ? $data['contentid']:" ",   
        "courseid" => isset($data['courseid']) ? $data['courseid']:" ",   
        "vendorid" =>  $vendorid,
        "paymentId" =>  isset($data['paymentId']) ? $data['paymentId']:" " , 
        "planId" => isset($data['planId']) ? $data['planId']:" " , 
    ];

     

$client = LambdaClient::factory(
    array(
        'version' => 'latest',
        'region'  => 'us-east-1'
    )
);
$result = $client->invokeAsync([
  'FunctionName' => 'actuator-jsonruleengine-dev',
  'InvokeArgs' => $Payload
]);
var_dump($result->get('Payload'));

$finalResult = json_decode($result);
errorlog_withlevel('addRewardsPoints POST  output=======>' . json_encode($finalResult), 3); 
return $finalResult;

Advertisement

Answer

<?php

/**
 * [getMOOCCouponListDetails description].
 *
 * @param [type] $data          [description]
 * @param [type] $vendorDetails [description]
 *
 * @return [type] [description]
 */

require_once 'vendor/autoload.php';
function addRewardsPoints($vendorid, $data)
{ 
    $Payload = [
        "subscriberid" => isset($data['subscriberid']) ? $data['subscriberid']:" ",
        "videocompletion" =>  isset($data['videocompletion']) ? $data['videocompletion']:" ",
        "profileid" =>  isset($data['profileid']) ? $data['profileid']:" ",  
        "contentid" =>  isset($data['contentid']) ? $data['contentid']:" ",   
        "courseid" => isset($data['courseid']) ? $data['courseid']:" ",   
        "vendorid" =>  $vendorid,
        "paymentId" =>  isset($data['paymentId']) ? $data['paymentId']:" " , 
        "planId" => isset($data['planId']) ? $data['planId']:" " ,  
        "profilename" => isset($data['profilename']) ? $data['profilename']:" " , 
    ];
    try {
 
        $client = new AwsLambdaLambdaClient(
            array(
                'version' => 'latest',
                'region'  => 'us-east-1'
            )
        );

        $result = $client->invoke([
            'FunctionName' => 'actuator-jsonruleengine-dev',
            'Payload' => json_encode($Payload)
        ]);
    

        errorlog_withlevel('addRewardsPoints POST  output=======>' . json_encode($result), 3); 
        
        return $result;
    }
    catch(Exception $e)
    {
        $errorData = formatError(1078);
        $errorData['reason'] = $e->getMessage();
        errorlog_withlevel('exception=======>' . json_encode($e->getMessage()), 3); 
    }
}
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement