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,
));
Related
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!
I am trying to use aws-sdk-php multipart copy to copy from one bucket to another bucket in different regions. It works when on the same regions, but not when in different regions using the below code:
$s3Client = new S3Client([
'region' => 'us-west-2',
'version' => '2006-03-01',
'credentials' => [
'key' => AWS_KEY_ID,
'secret' => AWS_SECRET,
]
]);
$copier = new MultipartCopy($s3Client, '/'.$from_bucket_name.'/'.$from_path,
[
'bucket' => 'toBucket',
'key' => $upload->client_id . '/videos/' . $upload->file_name, //to path
'part_size' => $part_size,
'concurrency' => $concurrency
]);
Any help on this would be greatly appreciated!
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',
In general, AWS S3 works fine in my web. However, I keep getting randomly these errors when downloading:
Error retrieving credentials from the instance profile metadata server. (cURL error 28: Operation timed out after {>1000} milliseconds with 0 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html))
Why? How can I prevent these errors from happening?
I am using AWS SDK PHP v3.
if are you using a Credential like below
$s3 = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'us-east-1',
'key' => "AKIAJAAAXXYASASASASDSUAG66MA",
'secret' => "8sZyAAAAXUSuUK3FJSDFSDS&D*SDSJFSFShjssa7Fx+GS9"
)
]);
then change to like this
$s3 = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'us-east-1',
'credentials' => array(
'key' => "AKIAJAAAXXYASASASASDSUAG66MA",
'secret' => "8sZyAAAAXUSuUK3FJSDFSDS&D*SDSJFSFShjssa7Fx+GS9"
)
]);
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)