-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathGetDistribution.php
74 lines (61 loc) · 2.35 KB
/
GetDistribution.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
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// snippet-start:[cloudfront.php.getdistribution.complete]
// snippet-start:[cloudfront.php.getdistribution.import]
require 'vendor/autoload.php';
use Aws\Exception\AwsException;
// snippet-end:[cloudfront.php.getdistribution.import]
/* ////////////////////////////////////////////////////////////////////////////
* Purpose: Gets information about an Amazon CloudFront distribution.
*
* Prerequisites: An existing Amazon CloudFront distribution.
*
* Inputs:
* - $cloudFrontClient: An initialized AWS SDK for PHP SDK client
* for CloudFront.
* - $distributionId: The distribution's ID.
*
* Returns: Information about the distribution; otherwise,
* the error message.
* ///////////////////////////////////////////////////////////////////////// */
// snippet-start:[cloudfront.php.getdistribution.main]
function getDistribution($cloudFrontClient, $distributionId)
{
try {
$result = $cloudFrontClient->getDistribution([
'Id' => $distributionId
]);
$message = '';
if (isset($result['Distribution']['Status'])) {
$message = 'The status of the distribution with the ID of ' .
$result['Distribution']['Id'] . ' is currently ' .
$result['Distribution']['Status'];
}
if (isset($result['@metadata']['effectiveUri'])) {
$message .= ', and the effective URI is ' .
$result['@metadata']['effectiveUri'] . '.';
} else {
$message = 'Error: Could not get the specified distribution. ' .
'The distribution\'s status is not available.';
}
return $message;
} catch (AwsException $e) {
return 'Error: ' . $e->getAwsErrorMessage();
}
}
function getsADistribution()
{
$distributionId = 'E1BTGP2EXAMPLE';
$cloudFrontClient = new Aws\CloudFront\CloudFrontClient([
'profile' => 'default',
'version' => '2018-06-18',
'region' => 'us-east-1'
]);
echo getDistribution($cloudFrontClient, $distributionId);
}
// Uncomment the following line to run this code in an AWS account.
// getsADistribution();
// snippet-end:[cloudfront.php.getdistribution.main]
// snippet-end:[cloudfront.php.getdistribution.complete]
// snippet-sourceauthor:[pccornel (AWS)]