Specify version when creating a aws-sdk-php client - php

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',
],

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!

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',

How to log in to AWS cognito user pool using PHP SDK

I am trying to log in the user to the AWS Cognito user pool using PHP SDK. I am following this tutorial, https://sanderknape.com/2017/02/getting-started-with-aws-cognito/. But I am getting the error.
Here is my code:
$credentials = array(
'key' => env('AWS_IAM_KEY', ''),
'secret' => env('AWS_IAM_SECRET', '')
);
//2014-06-30
$client = CognitoIdentityClient::factory(array('region' => env('AWS_REGION',''), 'version' => 'latest', $credentials));
$result = $client->adminInitiateAuth([
'AuthFlow' => 'ADMIN_NO_SRP_AUTH',
'ClientId' => COGNITO_APP_CLIENT_ID,
'UserPoolId' => COGNITO_USER_POOL_ID,
'AuthParameters' => [
'USERNAME' => "name",
'PASSWORD' => 'password',
],
]);
$accessToken = $result->get('AuthenticationResult')['AccessToken'];
When I run the code, I got this error:
InvalidArgumentException
Operation not found: AdminInitiateAuth
It is saying the AdminInitiiateAuth does not exist. But I am correctly following the tutorial. What is missing in my code?
The problem here is that CognitoIdentityClient does not contain the adminInitiateAuth functionality.
You will need to use the CognitoIdentityProviderClient

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,
));

how can I use aws credentials file for laravel 5

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',
],

Categories