create_invalidation ( $distribution_id, $caller_reference, $paths, $opt )

Creates a new invalidation request.

Access

public

Parameters

Parameter

Type

Required

Description

$distribution_id

string

Required

The distribution ID returned from create_distribution() or list_distributions().

$caller_reference

string

Required

A unique identifier for the request. A timestamp-appended string is recommended.

$paths

string
array

Required

One or more paths to set for invalidation. Pass a string for a single value, or an indexed array for multiple values. values.

$opt

array

Optional

An associative array of parameters that can have the following keys:

  • curlopts - array - Optional - A set of values to pass directly into curl_setopt(), where the key is a pre-defined CURLOPT_* constant.
  • returnCurlHandle - boolean - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.

Returns

Type

Description

CFResponse

A CFResponse object containing a parsed HTTP response.

Examples

Create a new CloudFront invalidation request.

In this example, we don’t know the file path to invalidate, so we’ll invalidate everything in the distribution.

$s3 = new AmazonS3();
$cdn = new AmazonCloudFront();

// Get the information about the distribution.
$distribution_info = $cdn->get_distribution_info('E2L6A3OZHQT5W4');

// Fetch the fully-qualified domain name for the origin bucket.
$origin_bucket_fqdn = (string) $distribution_info->body->DistributionConfig->S3Origin->DNSName;

// Strip the hostname, and only leave the bucket name.
$origin_bucket = substr($origin_bucket_fqdn, 0, -17); // Remove `.s3.amazonaws.com`

// Get the list of files from the S3 bucket.
$file_paths = $s3->get_object_list($origin_bucket);

// Create a new invalidation.
$response = $cdn->create_invalidation('E2L6A3OZHQT5W4', 'aws-php-sdk-test' . time(), $file_paths);

// Success?
var_dump($response->isOK());
Result:
bool(true)

Related Methods

See Also

Source

Method defined in services/cloudfront.class.php | Toggle source view (12 lines) | View on GitHub

public function create_invalidation($distribution_id, $caller_reference, $paths, $opt = null)
{
    if (!$opt) $opt = array();
    $opt['Paths'] = $paths;

    $path = '/distribution/' . $distribution_id . '/invalidation';
    $xml = $this->generate_invalidation_xml($caller_reference, $opt);

    $opt = array_merge($opt, array('path' => $path, 'xml' => $xml));

    return $this->authenticate('POST', $opt);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback