Skip to content

Instantly share code, notes, and snippets.

@nickfox-taterli
Created January 10, 2020 05:56
Show Gist options
  • Save nickfox-taterli/3ce354df34d0b5877a8c9a821487a167 to your computer and use it in GitHub Desktop.
Save nickfox-taterli/3ce354df34d0b5877a8c9a821487a167 to your computer and use it in GitHub Desktop.
AWS Cross Account PHP Script
<?php
require 'vendor/autoload.php';
$credentials = new Aws\Credentials\Credentials('x', 'x');
$sts = new Aws\Sts\StsClient([
'version' => 'latest',
'region' => 'us-east-1',
'credentials' => $credentials
]);
$credentials_result = $sts->assumeRole([
'RoleArn' => 'arn:aws:iam::066600000000:role/xxxxxxx',
'RoleSessionName' => 'newsession',
'DurationSeconds' => 43200
])['Credentials'];
$credentials = new Aws\Credentials\Credentials($credentials_result['AccessKeyId'], $credentials_result['SecretAccessKey'], $credentials_result['SessionToken']);
$s3 = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'us-east-1',
'credentials' => $credentials
]);
$buckets = $s3->listBuckets();
foreach ($buckets['Buckets'] as $bucket) {
echo $bucket['Name'] . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment