

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

# Verwaltung von CloudFront Amazon-Invalidierungen mithilfe der CloudFront API und der Version 3 AWS SDK für PHP
<a name="cloudfront-example-invalidation"></a>

Amazon CloudFront speichert Kopien statischer und dynamischer Dateien an weltweiten Edge-Standorten im Cache. Erstellen Sie zum Entfernen oder Aktualisieren einer Datei auf allen Edge-Standorten eine Aufhebung für alle Dateien bzw. für eine Gruppe von Dateien.

Die ersten 1.000 Aufhebungen jedes Kalendermonats sind kostenlos. Weitere Informationen zum Entfernen von Inhalten von einem CloudFront Edge-Standort finden Sie unter Dateien für [ungültig erklären](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html).

In den nachstehenden Beispielen wird Folgendes veranschaulicht:
+ Erstellen Sie eine Invalidierung der Verteilung mit. [CreateInvalidation](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-cloudfront-2018-11-05.html#createinvalidation)
+ Rufen Sie eine Distributions-Invalidierung ab mit. [GetInvalidation](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-cloudfront-2018-11-05.html#getinvalidation)
+ Listet Distributionen auf mit. [ListInvalidations](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-cloudfront-2018-11-05.html#listinvalidations)

Der gesamte Beispielcode für AWS SDK für PHP ist [hier verfügbar GitHub.](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/php/example_code)

## Anmeldeinformationen
<a name="examplecredentials"></a>

Bevor Sie den Beispielcode ausführen, konfigurieren Sie Ihre AWS Anmeldeinformationen wie unter beschrieben[Authentifizierung AWS mit AWS SDK für PHP Version 3](credentials.md). Importieren Sie dann die AWS SDK für PHP, wie unter beschrieben[Installation der AWS SDK für PHP Version 3](getting-started_installation.md).

Weitere Informationen zur Verwendung von Amazon CloudFront finden Sie im [Amazon CloudFront Developer Guide](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/).

## Erstellen Sie eine Invalidierung der Distribution
<a name="create-a-distribution-invalidation"></a>

Erstellen Sie eine Invalidierung der CloudFront Distribution, indem Sie den Pfad für die Dateien angeben, die Sie entfernen müssen. Dieses Beispiel hebt die Gültigkeit aller Dateien in der Verteilung auf, aber Sie können bestimmte Dateien unter `Items` identifizieren.

Verwenden Sie den Vorgang, um eine Invalidierung der CloudFront [CreateInvalidation](https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_CreateInvalidation.html)Verteilung zu erstellen.

 **Importe** 

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
```

 **Beispiel-Code** 

```
function createInvalidation(
    $cloudFrontClient,
    $distributionId,
    $callerReference,
    $paths,
    $quantity
) {
    try {
        $result = $cloudFrontClient->createInvalidation([
            'DistributionId' => $distributionId,
            'InvalidationBatch' => [
                'CallerReference' => $callerReference,
                'Paths' => [
                    'Items' => $paths,
                    'Quantity' => $quantity,
                ],
            ]
        ]);

        $message = '';

        if (isset($result['Location'])) {
            $message = 'The invalidation location is: ' . $result['Location'];
        }

        $message .= ' and the effective URI is ' . $result['@metadata']['effectiveUri'] . '.';

        return $message;
    } catch (AwsException $e) {
        return 'Error: ' . $e->getAwsErrorMessage();
    }
}

function createTheInvalidation()
{
    $distributionId = 'E17G7YNEXAMPLE';
    $callerReference = 'my-unique-value';
    $paths = ['/*'];
    $quantity = 1;

    $cloudFrontClient = new Aws\CloudFront\CloudFrontClient([
        'profile' => 'default',
        'version' => '2018-06-18',
        'region' => 'us-east-1'
    ]);

    echo createInvalidation(
        $cloudFrontClient,
        $distributionId,
        $callerReference,
        $paths,
        $quantity
    );
}

// Uncomment the following line to run this code in an AWS account.
// createTheInvalidation();
```

## Holen Sie sich eine Distributions-Invalidierung
<a name="get-a-distribution-invalidation"></a>

Verwenden Sie den Vorgang, um den Status und die Details einer CloudFront Verteilung für ungültig zu erklären. [GetInvalidation](https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_GetInvalidation.html)

 **Importe** 

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
```

 **Beispiel-Code** 

```
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();
```

## Ungültigerklärungen von Verteilungen auflisten
<a name="list-distribution-invalidations"></a>

Verwenden Sie den Vorgang, um alle aktuellen CloudFront Verteilungsungültigkeiten aufzulisten. [ListInvalidations](https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_ListInvalidations.html)

 **Importe** 

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
```

 **Beispiel-Code** 

```
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();
```