-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathListDistributions.php
61 lines (52 loc) · 1.96 KB
/
ListDistributions.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
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// snippet-start:[cloudfront.php.listdistribution.complete]
// snippet-start:[cloudfront.php.listdistribution.import]
require 'vendor/autoload.php';
use Aws\Exception\AwsException;
// snippet-end:[cloudfront.php.listdistribution.import]
/* ////////////////////////////////////////////////////////////////////////////
* Purpose: Gets information about Amazon CloudFront distributions.
*
* Prerequisites: At least one existing Amazon CloudFront distribution.
*
* Inputs:
* - $cloudFrontClient: An initialized AWS SDK for PHP SDK client
* for CloudFront.
*
* Returns: Information about existing distributions; otherwise,
* the error message.
* ///////////////////////////////////////////////////////////////////////// */
// snippet-start:[cloudfront.php.listdistribution.main]
function listDistributions($cloudFrontClient)
{
try {
$result = $cloudFrontClient->listDistributions([]);
return $result;
} catch (AwsException $e) {
exit('Error: ' . $e->getAwsErrorMessage());
}
}
function listTheDistributions()
{
$cloudFrontClient = new Aws\CloudFront\CloudFrontClient([
'profile' => 'default',
'version' => '2018-06-18',
'region' => 'us-east-2'
]);
$distributions = listDistributions($cloudFrontClient);
if (count($distributions) == 0) {
echo 'Could not find any distributions.';
} else {
foreach ($distributions['DistributionList']['Items'] as $distribution) {
echo 'The distribution with the ID of ' . $distribution['Id'] .
' has the status of ' . $distribution['Status'] . '.' . "\n";
}
}
}
// Uncomment the following line to run this code in an AWS account.
// listTheDistributions();
// snippet-end:[cloudfront.php.listdistribution.main]
// snippet-end:[cloudfront.php.listdistribution.complete]
// snippet-sourceauthor:[pccornel (AWS)]