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

Comment

3 Comments

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
I wouldn't say this is boring. I would say it is slightly interesting. I always thought Amazon used super efficient code for everything. Guess I was wrong.

by riben, Oct 17, 2019, 5:53 PM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
When building an Alexa skill to play youtube, I get how you feel. You must rely on documetation a lot, because tutorials can only get you so far.

by fath2012, Oct 22, 2019, 4:24 AM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
[code]
// 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.

[/quote]
Somebody once did a github search for discord access tokens, and hacked every bot that people accidentally exposed their access token for.
Moral: Never upload stuff with credentials onto github

by fath2012, Oct 22, 2019, 4:32 AM

Opinions expressed herein are my own and not necessarily those of AoPS Incorporated.

avatar

levans
Archives
- January 2025
+ September 2023
+ September 2022
+ August 2020
+ November 2019
+ March 2019
+ January 2019
+ December 2018
+ September 2016
+ August 2015
+ July 2015
+ April 2015
+ February 2015
+ October 2014
+ August 2014
+ March 2014
+ February 2014
+ October 2013
+ September 2013
+ August 2013
CoC
+ June 2013
+ April 2013
+ February 2013
+ November 2012
+ September 2012
+ August 2012
+ April 2012
+ February 2012
+ January 2012
+ November 2011
Shouts
Submit
  • beautiful css omg

    by yaxuan, Feb 10, 2025, 5:31 AM

  • hello I just saw this

    the CSS here is pro
    $\text{also what is this font}$

    by Yrock, Feb 4, 2025, 2:36 AM

  • hiii it's been a long time

    300th shout!! :D

    by evt917, Dec 20, 2024, 5:15 PM

  • @LostInBali, it's totally based on terminals.

    by levans, May 22, 2024, 12:09 AM

  • HIIII! This is beautiful CSS and it reminds me of bash!!!!!!!
    (I do hope you like terminals)

    by LostInBali, May 1, 2024, 8:41 AM

  • COOOOL BLOG!!

    by Yummo, Feb 4, 2024, 7:09 PM

  • geez 100k+ views

    by ujulee, Dec 5, 2023, 5:47 PM

  • HOW SO ORZ WHAT THE HECK

    by madeleinelee, Dec 5, 2023, 6:03 AM

  • hi $          $

    by Bob_Smart, Nov 4, 2023, 4:38 AM

  • I like this blog so much it's so impressive!

    by BabaLama, May 2, 2023, 1:26 AM

  • bump$    $

    by TethysTide, Nov 16, 2022, 4:18 PM

  • pls don't click my username thanks :)

    by RyanWang, Sep 28, 2022, 4:26 AM

  • aops* $     $

    by programmeruser, Sep 27, 2022, 9:51 PM

  • Hello!$    $

    by Peregrine11, Aug 29, 2022, 9:02 PM

  • this is the best blog on aopa

    by programmeruser, Jun 16, 2022, 12:10 AM

302 shouts
About Owner
  • Posts: 5190
  • Joined: Apr 27, 2007
Blog Stats
  • Blog created: Jul 27, 2011
  • Total entries: 105
  • Total visits: 107941
  • Total comments: 616
Search Blog
a