AWS Authentication and URL Parsing
by levans, Oct 17, 2019, 5:43 PM
It's amazing how poor Amazon AWS's documentation is. It's equally amazing how hard it is to find information on the web. The example below shows one way of authentication, although not the recommended way, and the parsing of an S3 formatted URL. I know, none of this is useful to anyone who reads my blog, but hey, it's supposed to be boring!
<?php require 'vendor/autoload.php'; // You should always load your AWS credentials from // somewhere outside of the codebase and outside // publicly accessible endpoints. Never hard code // credentials into your code. $s3cfg = [ 'version' => 'latest', 'region' => 'us-east-1', 'credentials' => [ 'key' => 'YourAWSKey', 'secret' => 'YourAWSSecret', ], ]; $s3 = new Aws\S3\S3Client($s3cfg); $url = 's3://sample-bucket/file/name.txt'; $s3UrlParser = new Aws\S3\S3UriParser(); $parsedUrl = $s3UrlParser->parse($url); print_r($parsedUrl);Output:
Array
(
[path_style] =>
[bucket] => sample-bucket
[key] => file/name.txt
[region] =>
)
This post has been edited 6 times. Last edited by levans, Oct 17, 2019, 5:51 PM