2018-09-14 17:57:46 -07:00
< ? php
2020-04-27 16:17:12 -07:00
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
2024-02-05 10:49:20 -07:00
2019-01-18 00:02:57 -08:00
// snippet-start:[cloudfront.php.getinvalidation.complete]
// snippet-start:[cloudfront.php.getinvalidation.import]
2018-09-14 17:57:46 -07:00
require 'vendor/autoload.php' ;
2024-02-05 10:49:20 -07:00
2018-09-14 17:57:46 -07:00
use Aws\Exception\AwsException ;
2024-02-05 10:49:20 -07:00
2019-01-18 00:02:57 -08:00
// snippet-end:[cloudfront.php.getinvalidation.import]
2024-02-05 10:49:20 -07:00
2020-04-27 16:17:12 -07:00
/* ////////////////////////////////////////////////////////////////////////////
* 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.
2018-09-14 17:57:46 -07:00
*
2020-04-27 16:17:12 -07:00
* Returns: Information about the invalidation; otherwise,
* the error message.
* ///////////////////////////////////////////////////////////////////////// */
2024-02-05 10:49:20 -07:00
2019-01-18 00:02:57 -08:00
// snippet-start:[cloudfront.php.getinvalidation.main]
2020-04-27 16:17:12 -07:00
function getInvalidation ( $cloudFrontClient , $distributionId , $invalidationId )
{
try {
$result = $cloudFrontClient -> getInvalidation ([
'DistributionId' => $distributionId ,
'Id' => $invalidationId ,
]);
2024-02-05 10:49:20 -07:00
2020-04-27 16:17:12 -07:00
$message = '' ;
2024-02-05 10:49:20 -07:00
2020-04-27 16:17:12 -07:00
if ( isset ( $result [ 'Invalidation' ][ 'Status' ])) {
$message = 'The status for the invalidation with the ID of ' .
$result [ 'Invalidation' ][ 'Id' ] . ' is ' .
$result [ 'Invalidation' ][ 'Status' ];
}
2024-02-05 10:49:20 -07:00
2020-04-27 16:17:12 -07:00
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.' ;
}
2024-02-05 10:49:20 -07:00
2020-04-27 16:17:12 -07:00
return $message ;
} catch ( AwsException $e ) {
return 'Error: ' . $e -> getAwsErrorMessage ();
2024-02-05 10:49:20 -07:00
}
2020-04-27 16:17:12 -07:00
}
2024-02-05 10:49:20 -07:00
2020-04-27 16:17:12 -07:00
function getsAnInvalidation ()
{
$distributionId = 'E1BTGP2EXAMPLE' ;
$invalidationId = 'I1CDEZZEXAMPLE' ;
2024-02-05 10:49:20 -07:00
2020-04-27 16:17:12 -07:00
$cloudFrontClient = new Aws\CloudFront\CloudFrontClient ([
'profile' => 'default' ,
'version' => '2018-06-18' ,
'region' => 'us-east-1'
2018-10-03 14:15:29 -07:00
]);
2024-02-05 10:49:20 -07:00
2020-04-27 16:17:12 -07:00
echo getInvalidation ( $cloudFrontClient , $distributionId , $invalidationId );
2018-10-30 20:53:20 -07:00
}
2024-02-05 10:49:20 -07:00
2020-04-27 16:17:12 -07:00
// Uncomment the following line to run this code in an AWS account.
// getsAnInvalidation();
2019-01-18 00:02:57 -08:00
// snippet-end:[cloudfront.php.getinvalidation.main]
// snippet-end:[cloudfront.php.getinvalidation.complete]
2020-04-27 16:17:12 -07:00
// snippet-sourceauthor:[pccornel (AWS)]