Last active
March 7, 2019 00:18
-
-
Save sodonnell/ab0fe94d68f119bbd90a1dc03fc140d1 to your computer and use it in GitHub Desktop.
Using the AWS PHP SDK to upload files to S3 bucket using EC2 Instance Profile (IAM Role) Credentials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'vendor/autoload.php'; | |
use Aws\Credentials\CredentialProvider; | |
use Aws\S3\S3Client; | |
$provider = CredentialProvider::instanceProfile(); | |
$mprovider = CredentialProvider::memoize($provider); | |
$s3 = new S3Client([ | |
'region' => 'us-east-1', | |
'version' => 'latest', | |
'credentials' => $mprovider | |
]); | |
$data = [ | |
'Bucket' => 'my-s3-bucket', | |
'Key' => 'path/to/upload/file/to.txt', | |
'Body' => 'Hello, S3.', | |
'ACL' => 'public-read' | |
]; | |
$result = $s3->putObject($data); | |
print_r($result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment