I am using amazon-php-sdk. In my application I'm accepting key and secret value from a form and passing for connecting to Aws. Here is my code.
<?php
require 'aws-autoloader.php';
use Aws\S3\S3Client;
try {
$s3Client = S3Client::factory(array(
'key' => 'my key',
'secret' => 'my secret key'
));
}
catch(S3Exception $e) {
echo 'Msg' . $e->getMessage();
}
?>
Testing the VPC Endpoint for S3 To check that your VPC Endpoint for S3 is working correctly, find the URL of your target bucket in the AWS console and use the hostname there as the target of a traceroute command on one of your virtual machines in your SDDC.
You cannot "ping a bucket" because bucket names are merely logical containers served by Amazon S3. There is no direct relationship between IP addresses and buckets. Resolving the DNS name of an S3 bucket would only return the address of an Amazon S3 server.
As Michael pointed out, you have to make an actual request to check the connection.AWS discourages any unnecessary validation requests which will affect the performance of your application and your usage bill.
But if you need to validate you can use ListBucket or HEAD request on a bucket.
Checkout this best practises article.
require 'vendor/autoload.php';
use Aws\S3\S3Client;
try {
// 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',
)
));
$buckets = $s3Client->listBuckets();
}
catch(Exception $e) {
exit($e->getMessage());
}
To answer your second question.You can use doesObjectExist function which returns a boolean.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With