-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathListInvalidations.php
77 lines (67 loc) · 2.56 KB
/
ListInvalidations.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
75
76
77
<?php
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// snippet-start:[cloudfront.php.listinvalidation.complete]
// snippet-start:[cloudfront.php.listinvalidation.import]
require 'vendor/autoload.php';
use Aws\Exception\AwsException;
// snippet-end:[cloudfront.php.listinvalidation.import]
/* ////////////////////////////////////////////////////////////////////////////
* Purpose: Gets information about Amazon CloudFront distribution
* invalidations.
*
* Prerequisites: At least one existing Amazon CloudFront invalidation for the
* specified distribution.
*
* Inputs:
* - $cloudFrontClient: An initialized AWS SDK for PHP SDK client
* for CloudFront.
* - $distributionId: The ID of the distribution to get invalidation
* information about.
*
* Returns: Information about existing distribution invalidations; otherwise,
* the error message.
* ///////////////////////////////////////////////////////////////////////// */
// snippet-start:[cloudfront.php.listinvalidation.main]
function listInvalidations($cloudFrontClient, $distributionId)
{
try {
$result = $cloudFrontClient->listInvalidations([
'DistributionId' => $distributionId
]);
return $result;
} catch (AwsException $e) {
exit('Error: ' . $e->getAwsErrorMessage());
}
}
function listTheInvalidations()
{
$distributionId = 'E1WICG1EXAMPLE';
$cloudFrontClient = new Aws\CloudFront\CloudFrontClient([
'profile' => 'default',
'version' => '2018-06-18',
'region' => 'us-east-1'
]);
$invalidations = listInvalidations(
$cloudFrontClient,
$distributionId
);
if (isset($invalidations['InvalidationList'])) {
if ($invalidations['InvalidationList']['Quantity'] > 0) {
foreach ($invalidations['InvalidationList']['Items'] as $invalidation) {
echo 'The invalidation with the ID of ' . $invalidation['Id'] .
' has the status of ' . $invalidation['Status'] . '.' . "\n";
}
} else {
echo 'Could not find any invalidations for the specified distribution.';
}
} else {
echo 'Error: Could not get invalidation information. Could not get ' .
'information about the specified distribution.';
}
}
// Uncomment the following line to run this code in an AWS account.
// listTheInvalidations();
// snippet-end:[cloudfront.php.listinvalidation.main]
// snippet-end:[cloudfront.php.listinvalidation.complete]
// snippet-sourceauthor:[pccornel (AWS)]