how can I use aws credentials file for laravel 5 - php

Is there a way to use laravel's SQS queue w/out putting access key and secret in the config? ie: use aws credentials file?

Laravel instantiates a SqsClient here, passing through options from app/config/queue.php.
It looks like you're interested the 'profile' option described here.
use Aws\Sqs\SqsClient;
$client = SqsClient::factory(array(
'profile' => '<profile in your aws credentials file>',
'region' => '<region name>'
));
Seems to me you should just be able to set a 'profile' option on your queue config
'sqs' => [
'driver' => 'sqs',
'profile' => '/path/to/your/credeitials/profile/here',
'queue' => 'your-queue-url',
'region' => 'us-east-1',
],

Related

Upload Object (image file) to Linode Object Storage using PHP (Laravel) with S3Client

What could be the possible solution for this? I'm trying to upload an Object (Image file) to my Linode Object Storage, I have already set up the configuration and credentials but I'm still having trouble doing it. Can someone help me?
Code:
$config = [
'version' => 'latest',
'region' => config('filesystems.disks.s3.region'),
'scheme' => 'http',
'endpoint' => config('filesystems.disks.s3.endpoint'),
'credentials' => [
'key' => config('filesystems.disks.s3.key'),
'secret' => config('filesystems.disks.s3.secret'),
],
'debug' => true
];
$client = new S3Client($config);
return $client->putObject([
'Bucket' => config('filesystems.disks.s3.bucket'),
'Key' => $filename,
'SourceFile' => $file
]);
Here's the exception error:
check me please
Hoping to have some feedback here, thank you!

Registering custom\additional routes for a laravel websocket server?

So I'm using beyondcode/laravel-websockets to setup a WS server and I want to work with multiple apps so I did this in config\websockets.php:
'apps' => [
[
'id' => env('A_APP_ID'),
'name' => env('A_APP_NAME'),
'key' => env('A_APP_KEY'),
'secret' => env('A_APP_SECRET'),
'path' => env('A_APP_PATH'),
'capacity' => null,
'enable_client_messages' => false,
'enable_statistics' => true,
],
[
'id' => env('B_APP_ID'),
'name' => env('B_APP_NAME'),
'key' => env('B_APP_KEY'),
'secret' => env('B_APP_SECRET'),
'path' => env('B_APP_PATH'),
'capacity' => null,
'enable_client_messages' => false,
'enable_statistics' => true,
],
],
However, I want to implement custom handlers for each app and I've been trying this, routes\web.php:
WebSocketsRouter::webSocket('app/{appKey}/bapp', \App\WebSockets\BAppWebSocketHandler::class);
//Also tried this..
WebSocketsRouter::webSocket('app/{appKey}', \App\WebSockets\AAppWebSocketHandler::class);
//and created `AAppWebSocketHandler` which does nothing but calling parent (WebSocketHandler) methods
Problem is it's always using one handler for all apps despite the difference in routes.
Any ideas?
Thanks!
You don't have to define routes while defining multiple apps in the config. Instead configure Echo to work with separate app key and secret. If you want to use custom handler with own logic, then remove them from configs. Also note that, you won't get any channel or pusher client library support. You will have to implement your own authentication as well.

AWS Credential error

I am trying to connect to AWS from my php application(Laravel). My intention is to use the AWS Media convert Service. Please see the code I have used.
$client = new MediaConvertClient([
'profile' => 'default',
'version' => '2017-08-29',
'region' => 'us-west-1',
'credentials' => [
'key' => $key,
'secret' => $secret,
],
]);
$URI = $client->getEndpoint();
$endpoints= $client->describeEndpoints();
This is the error I am getting.
Cannot read credentials from /.aws/credentials
Does anyone have an idea about how to resolve this issues?
Finally, I got the answer. Removing the below line helped me to read the credential from $key and $secret (which is defined in the configuration file)
'profile' => 'default',

Delete object using v3 ASK PHP SDK

I'm having trouble logging in:
require 'aws-autoloader.php';
$client = new Aws\S3\S3Client([
'version' => 'latest',
'region' => REGION,
'endpoint' => HOST,
'credentials' => [
'key' => AWS_KEY,
'secret' => AWS_SECRET_KEY,
],
]);
$result = $client->deleteObject(array(
'Bucket' => $BucketName,
'Key' => $FileKey,
));
The $client object is never created. If I run it without the credentials it creates the $client. The Amazon docs say this is how to hardcode credentials. The docs have varying examples from previous sdk's which is really confusing. What's the correct way for deleting an object from V3? I'm not using composer if that matters.
UPDATE
The code works but the endpoint value is causing issues. if I use http://bucket.s3.amazonaws.com/ as the host it tries to fetch http://bucket.bucket.s3.amazonaws.com/key and throws a 404 not found, if i change it to http://s3.amazonaws.com it doesn't work at all, if I remove the host it tries fetching http://s3.amazonaws.com/bucket/key which gives a 204 status message and the deletemarker is still false and the file isn't deleted. I dunno how to make deleteObject create the correct effectiveuri in the result. I dunno what the 204 status means.
SOLUTION
The code works fine without the endpoint field. I hadn't put DELETE as allowed in the S3 CORRS. It works now.
require 'aws-autoloader.php';
$client = new Aws\S3\S3Client([
'version' => 'latest',
'region' => REGION,
'credentials' => [
'key' => AWS_KEY,
'secret' => AWS_SECRET_KEY,
],
]);
$result = $client->deleteObject(array(
'Bucket' => $BucketName,
'Key' => $FileKey,
));

Specify version when creating a aws-sdk-php client

I'm using Laravel Stapler to save model attachments to s3. Reading through the docs I came up with the following code and stuck it in the model's save method.
$this->hasAttachedFile('recording', [
'url' => '/recording/:attachment/:id_partition/:style/:filename',
'storage' => 's3',
's3_client_config' => [
'key' => 'accessKey',
'secret' => 'secretKey',
'region' => 'us-east-1'
],
's3_object_config' => [
'Bucket' => 'bucket.aws.com'
],
]);
When I find() a model, set the attachment, and run save() I get:
PHP Fatal error: Uncaught exception 'InvalidArgumentException' with message 'version is a required configuration setting when creating a client.' in /Users/myName/Code/projectName/vendor/aws/aws-sdk-php/src/Common/ClientFactory.php:99
The ClientFactory create() method required a 'version' to be set. Looking through the laravel-stapler and stapler docs I don't see anything mentioning a version. I'm using the most recent version of laravel-stapler with laravel 4.
Is there something I'm missing here?
Even though it wasn't in the docs I had to actually add a version when configuring s3.
's3_client_config' => [
'key' => 'accessKey',
'secret' => 'secretKey',
'region' => 'us-east-1',
'version' => 'latest',
],

Categories