

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# AWS SDK for PHP 버전 3를 사용하여 Amazon CloudWatch 경보에서 경보 작업 사용
<a name="cw-examples-using-alarm-actions"></a>

경보 작업을 사용하여 Amazon EC2 인스턴스를 자동으로 중지, 종료, 재부팅 또는 복구하는 경보를 생성합니다. 인스턴스를 더는 실행할 필요가 없을 때 중지 또는 종료 작업을 사용할 수 있습니다. 재부팅 및 복구 작업을 사용하여 인스턴스를 자동으로 재부팅할 수 있습니다.

다음 예제에서는 다음과 같은 작업을 하는 방법을 보여줍니다.
+ [EnableAlarmActions](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-monitoring-2010-08-01.html#enablealarmactions)를 사용하여 지정된 경보에 대한 작업을 활성화합니다.
+ [DisableAlarmActions](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-monitoring-2010-08-01.html#disablealarmactions)를 사용하여 지정된 경보에 대한 작업을 비활성화합니다.

AWS SDK for PHP에 대한 모든 예제 코드는 [GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/php/example_code)에서 사용할 수 있습니다.

## 보안 인증 정보
<a name="examplecredentials"></a>

예제 코드를 실행하기 전에 [AWS SDK for PHP 버전 3을 AWS 사용하여 로 인증](credentials.md)에 설명된 대로 AWS 보안 인증을 구성합니다. 그 다음 [AWS SDK for PHP 버전 3 설치](getting-started_installation.md)에 설명된 AWS SDK for PHP를 가져옵니다.

## 경보 작업 활성화
<a name="enable-alarm-actions"></a>

 **가져옵니다**.

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

use Aws\CloudWatch\CloudWatchClient;
use Aws\Exception\AwsException;
```

 **샘플 코드** 

```
function enableAlarmActions($cloudWatchClient, $alarmNames)
{
    try {
        $result = $cloudWatchClient->enableAlarmActions([
            'AlarmNames' => $alarmNames
        ]);

        if (isset($result['@metadata']['effectiveUri'])) {
            return 'At the effective URI of ' .
                $result['@metadata']['effectiveUri'] .
                ', actions for any matching alarms have been enabled.';
        } else {
            return'Actions for some matching alarms ' .
                'might not have been enabled.';
        }
    } catch (AwsException $e) {
        return 'Error: ' . $e->getAwsErrorMessage();
    }
}

function enableTheAlarmActions()
{
    $alarmNames = array('my-alarm');

    $cloudWatchClient = new CloudWatchClient([
        'profile' => 'default',
        'region' => 'us-east-1',
        'version' => '2010-08-01'
    ]);

    echo enableAlarmActions($cloudWatchClient, $alarmNames);
}

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

## 경보 작업 비활성화
<a name="disable-alarm-actions"></a>

 **가져옵니다**.

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

use Aws\CloudWatch\CloudWatchClient;
use Aws\Exception\AwsException;
```

 **샘플 코드** 

```
function disableAlarmActions($cloudWatchClient, $alarmNames)
{
    try {
        $result = $cloudWatchClient->disableAlarmActions([
            'AlarmNames' => $alarmNames
        ]);

        if (isset($result['@metadata']['effectiveUri'])) {
            return 'At the effective URI of ' .
                $result['@metadata']['effectiveUri'] .
                ', actions for any matching alarms have been disabled.';
        } else {
            return 'Actions for some matching alarms ' .
                'might not have been disabled.';
        }
    } catch (AwsException $e) {
        return 'Error: ' . $e->getAwsErrorMessage();
    }
}

function disableTheAlarmActions()
{
    $alarmNames = array('my-alarm');

    $cloudWatchClient = new CloudWatchClient([
        'profile' => 'default',
        'region' => 'us-east-1',
        'version' => '2010-08-01'
    ]);

    echo disableAlarmActions($cloudWatchClient, $alarmNames);
}

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