

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 EC2 Amazon-Instances mit AWS SDK für PHP Version 3
<a name="ec2-examples-managing-instances"></a>

In den nachstehenden Beispielen wird Folgendes veranschaulicht:
+ Beschreiben Sie EC2 Amazon-Instances mithilfe von [DescribeInstances](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-ec2-2016-11-15.html#describeinstances).
+ Aktivieren Sie die detaillierte Überwachung für eine laufende Instance mithilfe von [MonitorInstances](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-ec2-2016-11-15.html#monitorinstances).
+ Deaktivieren Sie die Überwachung für eine laufende Instanz mit [UnmonitorInstances](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-ec2-2016-11-15.html#unmonitorinstances).
+ Starten Sie ein Amazon EBS-backed AMI, das Sie zuvor nicht mehr verwenden. [StartInstances](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-ec2-2016-11-15.html#startinstances)
+ Stoppen Sie die Verwendung einer Amazon EBS-gestützten Instance. [StopInstances](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-ec2-2016-11-15.html#stopinstances)
+ Fordern Sie einen Neustart einer oder mehrerer Instances an mit. [RebootInstances](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-ec2-2016-11-15.html#rebootinstances)

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).

## Beschreiben von Instances
<a name="describe-instances"></a>

 **Importe** 

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

use Aws\Ec2\Ec2Client;
```

 **Beispiel-Code** 

```
$ec2Client = new Aws\Ec2\Ec2Client([
    'region' => 'us-west-2',
    'version' => '2016-11-15',
    'profile' => 'default'
]);
$result = $ec2Client->describeInstances();
echo "Instances: \n";
foreach ($result['Reservations'] as $reservation) {
    foreach ($reservation['Instances'] as $instance) {
        echo "InstanceId: {$instance['InstanceId']} - {$instance['State']['Name']} \n";
    }
}
```

## Aktivieren und deaktivieren Sie die Überwachung
<a name="enable-and-disable-monitoring"></a>

 **Importe** 

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

 **Beispiel-Code** 

```
$ec2Client = new Aws\Ec2\Ec2Client([
    'region' => 'us-west-2',
    'version' => '2016-11-15',
    'profile' => 'default'
]);

$instanceIds = ['InstanceID1', 'InstanceID2'];

$monitorInstance = 'ON';

if ($monitorInstance == 'ON') {
    $result = $ec2Client->monitorInstances([
        'InstanceIds' => $instanceIds
    ]);
} else {
    $result = $ec2Client->unmonitorInstances([
        'InstanceIds' => $instanceIds
    ]);
}

var_dump($result);
```

## Starten und beenden Sie eine Instanz
<a name="start-and-stop-an-instance"></a>

 **Importe** 

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

 **Beispiel-Code** 

```
$ec2Client = new Aws\Ec2\Ec2Client([
    'region' => 'us-west-2',
    'version' => '2016-11-15',
    'profile' => 'default'
]);

$action = 'START';

$instanceIds = ['InstanceID1', 'InstanceID2'];

if ($action == 'START') {
    $result = $ec2Client->startInstances([
        'InstanceIds' => $instanceIds,
    ]);
} else {
    $result = $ec2Client->stopInstances([
        'InstanceIds' => $instanceIds,
    ]);
}

var_dump($result);
```

## Neustarten einer Instance
<a name="reboot-an-instance"></a>

 **Importe** 

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

 **Beispiel-Code** 

```
$ec2Client = new Aws\Ec2\Ec2Client([
    'region' => 'us-west-2',
    'version' => '2016-11-15',
    'profile' => 'default'
]);

$instanceIds = ['InstanceID1', 'InstanceID2'];

$result = $ec2Client->rebootInstances([
    'InstanceIds' => $instanceIds
]);

var_dump($result);
```