SIGN IN SIGN UP

Welcome to the AWS Code Examples Repository. This repo contains code examples used in the AWS documentation, AWS SDK Developer Guides, and more. For more information, see the Readme.md file below.

0 0 0 Java
<?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'
2018-09-21 18:59:28 -07:00
]);
echo getDistribution($cloudFrontClient, $distributionId);
2018-10-30 20:53:20 -07:00
}
// 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)]