AWS Credential error - php

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

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!

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

Amazon ec2 not instantiate with php

I am working on amazon ec2. When i integrated the code giving following error
Fatal error: Uncaught exception 'Aws\Exception\CredentialsException' with message 'Error retrieving credentials from the instance profile metadata server. (cURL error 28: Connection timed out after 1996 milliseconds
Here is my code
require __DIR__ . '/aws.phar';
$client = Aws\S3\S3Client::factory([
'key' => '[********]',
'secret' => '[************]',
'region' => '[us-east-1]', // (e.g., us-east-1)
'version' => 'latest'
]);
echo $client->listBuckets();
Key and Secret shouldn't include [ and ]. Can you try:
'key' => '********',
'secret' => '************',
'region' => 'us-east-1',
Passing credentials into a client factory method
// Instantiate the S3 client with your AWS credentials
$s3Client = S3Client::factory(array(
'credentials' => array(
'key' => 'YOUR_AWS_ACCESS_KEY_ID',
'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY',
)
));

Server error 500 while trying to instantiate an Amazon s3 client

I am getting server error 500 while opening my PHP file in a browser.
This is my config.php file:
<?php
return [
's3' => [
'key' => 'xxx',
'secret' => 'xxxx',
'region' => 'ap-southeast-1',
'bucket' => 'abc.def'
]
];
?>
The start.php file:
<?php
require '../vendor/autoload.php';
use Aws\S3\S3Client;
$config = require('config.php');
$s3 = new S3Client([
'region' => $config['s3Client']['region'],
'version' => 'latest',
'credentials' => [
'key' => $config['s3Client']['key'],
'secret' => $config['s3Client']['secret'],
],
]);
?>
I am getting a 500 error when I try to instantiate an Amazon S3 client. I am new to PHP and AWS. What is wrong with the code?
Please make sure you have the right permissions on the designated files you try to read (owner and group)

Categories