php aws sdk cant invoke lambda function - aws-lambda

Using the below PHP code to invoke lambda function but i am getting the below error. Looked at the PHP AWS api docuumentation not able to find whats causing issue.
Receiving the below error from aws php sdk
PHP Warning: Illegal string offset 'StatusCode' in /var/www/html/Guzzle/Service/Command/LocationVisitor/Response/StatusCodeVisitor.php on line 21
PHP Warning: Illegal string offset 'FunctionError' in /var/www/html/Guzzle/Service/Command/LocationVisitor/Response/HeaderVisitor.php on line 24
PHP Warning: Illegal string offset 'LogResult' in /var/www/html/Guzzle/Service/Command/LocationVisitor/Response/HeaderVisitor.php on line 24
PHP Catchable fatal error: Argument 1 passed to Guzzle\Service\Resource\Model::__construct() must be of the type array, string given, called in /var/www/html/Guzzle/Service/Command/OperationResponseParser.php on line 86 and defined in /var/www/html/Guzzle/Service/Resource/Model.php on line 20
use Aws\Lambda\LambdaClient;
$client = LambdaClient::factory(array(
'credentials' => array(
'key' => $f_key,
'secret' => $f_secret,
),
'region' => 'ap-southeast-2'
));
try {
echo "new invoke" . "\n";
$result = $client->invoke(array(
// FunctionName is required
'FunctionName' => 'hello_wo’,
));
}catch(Exception $e) {
echo 'Error retrieving lambd error message code-' . $e->getCode . '-error message-' . $e->getMessage() ;
}

Try this:
$client = LambdaClient::factory([
'key' => $f_key,
'secret' => $f_secret,
'region' => 'ap-southeast-2'
]);

Related

Using aws-s3-v3 with laravel and digitalocean spaces results in error 501 not implemented

I am trying to upload some files to a s3 compatible storage from digitalocean (spaces) using Laravel 8 and flysystem-aws-s3-v3.
But when I submit those files I'm getting this error:
Aws\S3\Exception\S3Exception
Error executing "PutObject" on "//SPACES_NAME.nyc3.digitaloceanspaces.com/SPACES_NAME.nyc3.digitaloceanspaces.com"; AWS HTTP error: Server error: `PUT http://SPACES_NAME.nyc3.digitaloceanspaces.com/SPACES_NAME.nyc3.digitaloceanspaces.com` resulted in a `501 Not Implemented` response: <?xml version="1.0" encoding="UTF-8"?><Error><Code>NotImplemented</Code><RequestId>tx00000000000000bf40fd9-00605636a9-96 (truncated...) NotImplemented (server): - <?xml version="1.0" encoding="UTF-8"?><Error><Code>NotImplemented</Code><RequestId>tx00000000000000bf40fd9-0060
5636a9-9617be5-nyc3c9617be5-nyc3c-nyc3-zg03
Here are my digitalocean constants from .env:
DO_SPACES_ACCESS_KEY=[edit]
DO_SPACES_SECRET_ACCESS_KEY=[edit]
DO_SPACES_ENDPOINT=nyc3.digitaloceanspaces.com
DO_SPACES_REGION=nyc3
DO_SPACES_BUCKET=SPACES_NAME
DO_URL=https://SPACES_NAME.nyc3.cdn.digitaloceanspaces.com
And here is the config part from config/filesystem.php:
'disks' => [
...
'do' => [
'driver' => 's3',
'key' => env('DO_SPACES_ACCESS_KEY'),
'secret' => env('DO_SPACES_SECRET_ACCESS_KEY'),
'region' => env('DO_SPACES_REGION'),
'bucket' => env('DO_SPACES_BUCKET'),
'endpoint' => env('DO_SPACES_ENDPOINT'),
'url' => env('DO_URL'),
],
],
And this is the test method that I'm using to process uploads:
Route::post('upload', function(){
$extension = request()->file('file')->extension();
$path = Storage::disk('do')->putFileAs('upload', request()->file('file'), time() . '.' .$extension, 'public');
});
Any thoughts on how this 501 not implemented error could be fixed? I see that the url for some reason appears twice and I think that that has something to do with it :-?
I solved the same problem as follows:
Add the following endpoint to the .env file
DO_SPACES_ENDPOINT=https://SPACES_NAME.nyc3.digitaloceanspaces.com
Add an option in the config/filesystem.php file to your DO Space.
'bucket_endpoint' => true
Clear the cache.

Indipay parameter missing exception

I am sending all the parameters required by indipay but still i am getting a parameter missing exception. If i send the static values then it is working fine.
$parameters = [
'purpose' => 'Application Fee for '.$regnId,
'buyer_name' => $request->s_fname.' '.$request->s_lname,
'amount' => env('APPLICATION_FEE'),
];
$order = Indipay::prepare($parameters);
return Indipay::process($order);
IndipayParametersMissingException in InstaMojoGateway.php line 119 at
InstaMojoGateway->checkParameters(array('redirect_url' =>
'http://127.0.0.1:8000/parent/response/indipay', 'purpose' =>
'Application Fee for GKB_19LKG_000019', 'buyer_name' => 'asdasd
asdasd', 'amount' => '200')) in InstaMojoGateway.php line 41
I finally found the answer.
The indipay package didn't gave the correct error. There was no parameter missing in the request. There was a max size issue in the validator function for the instamojo payment gateway.

Guzzle 6 Async request return Argument 1 passed must be of the type array, string given,

I'm trying to make an asynchronous POST call, but guzzle call returns the following error:
" ErrorException in Request.php line 220:
Argument 1 passed to Symfony\Component\HttpFoundation\Request::__construct() must be of the type array, string given, called in C:\Program Files ...\app\Http\Controllers\ConfirmAccountController.php on line 87 and defined "
In ConfirmAccountController:
$client = new Client(['base_uri' => 'correct_api_address']);
$request = new Request('POST', 'testpromoboiler/updateUser', [
'query' => ['token' => $user->sdg_token ,
'address' => $user->address ,
]
]);
$promise = $client->sendAsync($request)->then(function ($response) {
echo 'I completed! ' . $response->getBody();
});
$promise->wait();
Why I get this error?
I have done two other synchronous calls and everything went well.
Thanks
That code instantiates Laravel frameworks Request class.
Use guzzles request method instead:
$request = $client->request('POST', 'testpromoboiler/updateUser', [
'query' => ['token' => $user->sdg_token ,
'address' => $user->address ,
]
]);

Php code working on local server but giving syntax error on live server

Code:
function getUserId($userName) {
$myModel = new MY_Model();
$requiredFields = "id";
$whereClause = [ // line number 35
"is_active" => 'ACTIVE',
"user_name" => $userName
];
$userId = $myModel->select("users", $requiredFields, $whereClause);
return $userId;
}
Error:
Parse error: syntax error, unexpected '[' in /home/com/public_html/_apis/application/helpers/custom_helper.php on line 35
A PHP Error was encountered
Severity: Parsing Error
Message: syntax error, unexpected '['
Filename: helpers/custom_helper.php
Line Number: 35
Backtrace:
Replace Where Clause with this (Hope this help) :
$whereClause = array( // line number 35
"is_active" => 'ACTIVE',
"user_name" => $userName
);
Try this
$whereClause = array();
$whereClause['is_active'] = 'ACTIVE';
$whereClause['user_name'] = $userName;

Testing Laravel-Excel download

I'm using following package: https://github.com/Maatwebsite/Laravel-Excel at version 2 with Laravel version 5.1
I've have got controller method with following code:
....
return Excel::create('List', function($excel) use ($list)
{
$excel->sheet('List', function($sheet) use ($list)
{
$sheet->fromModel($list);
});
})
->download('csv');
and simple test like this:
$this->call('GET', 'route/to/csv', [
'param' => 'value',
]);
$this->dump();
Above test outputs [ERROR]: Headers already sent from this line of the package.
Controller method works fine, but can't test it.
I've tried to run phpunit with --stderr param. In that case, no error is thrown, but it just dumps output of CSV file to console and exits.
I've also tried to run test with #runInSeparateProcess annotation and got errors like:
PHPUnit_Framework_Exception: PHP Notice: Constant LARAVEL_START already defined in bootstrap/autoload.php on line 3
....
PHP Fatal error: Uncaught exception 'ReflectionException' with message 'Class env does not exist' in vendor/laravel/framework/src/Illuminate/Container/Container.php:736
Could this be a bug in Laravel-Excel package or I'm testing it wrong?
Thats because the way the download method works in laravel-excel is by setting headers. You want to avoid that, and instead do all the work your self by returning laravel Responses.
Try this instead:
$file = Excel::create('List', function($excel) use ($list) {
$excel->sheet('List', function($sheet) use ($list)
{
$sheet->fromModel($list);
});
})->string('xls');
return new Response($file, 200, [
'Content-Type' => 'application/vnd.ms-excel; charset=UTF-8',
'Content-Disposition' => 'attachment; filename="' . $file->filename . '.' . $file->ext . '"',
'Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT', // Date in the past
'Last-Modified' => Carbon::now()->format('D, d M Y H:i:s'),
'Cache-Control' => 'cache, must-revalidate',
'Pragma' => 'public',
]);
The key difference is to use the string() method which will return the binary data for the excel file and allows you to pass it as the data for a response.

Resources