-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathGetInvalidation.php
80 lines (67 loc) · 2.59 KB
/
GetInvalidation.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
78
79
80
<?php
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// snippet-start:[cloudfront.php.getinvalidation.complete]
// snippet-start:[cloudfront.php.getinvalidation.import]
require 'vendor/autoload.php';
use Aws\Exception\AwsException;
// snippet-end:[cloudfront.php.getinvalidation.import]
/* ////////////////////////////////////////////////////////////////////////////
* Purpose: Gets information about an invalidation for an
* Amazon CloudFront distribution.
*
* Prerequisites: An existing Amazon CloudFront distribution and a
* corresponding invalidation.
*
* Inputs:
* - $cloudFrontClient: An initialized AWS SDK for PHP SDK client
* for CloudFront.
* - $distributionId: The distribution's ID.
* - $invalidationId: The invalidation ID.
*
* Returns: Information about the invalidation; otherwise,
* the error message.
* ///////////////////////////////////////////////////////////////////////// */
// snippet-start:[cloudfront.php.getinvalidation.main]
function getInvalidation($cloudFrontClient, $distributionId, $invalidationId)
{
try {
$result = $cloudFrontClient->getInvalidation([
'DistributionId' => $distributionId,
'Id' => $invalidationId,
]);
$message = '';
if (isset($result['Invalidation']['Status'])) {
$message = 'The status for the invalidation with the ID of ' .
$result['Invalidation']['Id'] . ' is ' .
$result['Invalidation']['Status'];
}
if (isset($result['@metadata']['effectiveUri'])) {
$message .= ', and the effective URI is ' .
$result['@metadata']['effectiveUri'] . '.';
} else {
$message = 'Error: Could not get information about ' .
'the invalidation. The invalidation\'s status ' .
'was not available.';
}
return $message;
} catch (AwsException $e) {
return 'Error: ' . $e->getAwsErrorMessage();
}
}
function getsAnInvalidation()
{
$distributionId = 'E1BTGP2EXAMPLE';
$invalidationId = 'I1CDEZZEXAMPLE';
$cloudFrontClient = new Aws\CloudFront\CloudFrontClient([
'profile' => 'default',
'version' => '2018-06-18',
'region' => 'us-east-1'
]);
echo getInvalidation($cloudFrontClient, $distributionId, $invalidationId);
}
// Uncomment the following line to run this code in an AWS account.
// getsAnInvalidation();
// snippet-end:[cloudfront.php.getinvalidation.main]
// snippet-end:[cloudfront.php.getinvalidation.complete]
// snippet-sourceauthor:[pccornel (AWS)]