-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.php
48 lines (41 loc) · 1.55 KB
/
script.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
require './vendor/autoload.php';
use Aws\S3\S3Client;
use Aws\Credentials\CredentialProvider;
use Aws\Exception\AwsException;
$waitTimeInSeconds = $_SERVER['WAIT_TIME_IN_SECONDS'] ?? null;
if (null === $waitTimeInSeconds) {
throw new \Exception('Missing WAIT_TIME_IN_SECONDS env var.');
}
echo sprintf('WAIT_TIME_IN_SECONDS env var: %s', $waitTimeInSeconds) . PHP_EOL;
$waitTimeInSeconds = (int) $waitTimeInSeconds;
echo "Using AWS SDK for PHP version " . Aws\Sdk::VERSION . PHP_EOL;
$provider = CredentialProvider::assumeRoleWithWebIdentityCredentialProvider();
$count = 0;
$startDate = time();
while (true) {
//Create a S3Client
$s3Client = new S3Client([
//'profile' => 'default',
'provider' => $provider,
'region' => 'us-west-2',
'version' => '2006-03-01'
]);
$date = date('Y-m-d H:i:s');
//Listing all S3 Bucket
try {
$buckets = $s3Client->listBuckets();
// foreach ($buckets['Buckets'] as $bucket) {
// echo sprintf(' %s%s', $bucket['Name'], PHP_EOL);
// }
echo "Found " . sizeof($buckets['Buckets']) . " buckets." . PHP_EOL;
} catch (AwsException $e) {
echo "Error listing buckets: {$e->getMessage()}" . PHP_EOL;
}
$count++;
$runMins = (time() - $startDate) / 60;
echo "###" . PHP_EOL . "Token retrieved {$count} times" . PHP_EOL;
echo "Script has been running for {$runMins} min" . PHP_EOL . "###" . PHP_EOL;
echo sprintf('%s Sleeping %s seconds%s', $date, $waitTimeInSeconds, PHP_EOL);
sleep($waitTimeInSeconds);
}