

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

# CodePipeline 이벤트 모니터링
<a name="detect-state-changes-cloudwatch-events"></a>



자체 애플리케이션, software-as-a-service(SaaS) 애플리케이션 및에서 실시간 데이터 스트림을 제공하는 EventBridge에서 CodePipeline 이벤트를 모니터링할 수 있습니다 AWS 서비스. EventBridge는 해당 데이터를 AWS Lambda 및 Amazon Simple Notification Service와 같은 대상으로 라우팅합니다. 이러한 이벤트는 Amazon CloudWatch Events에 나타나는 이벤트와 동일하며, AWS 리소스의 변경 사항을 설명하는 시스템 이벤트의 스트림을 거의 실시간 제공합니다. 자세한 내용은 *EventBridge User Guide(EventBridge 사용 설명서)*의 [What Is EventBridge?(EventBridge란?)](https://docs.aws.amazon.com/eventbridge/latest/userguide/)를 참조하세요.

**참고**  
Amazon EventBridge는 이벤트를 관리하는 데 선호되는 방법입니다. Amazon CloudWatch Events와 EventBridge는 기본 서비스 및 API가 동일하지만 EventBridge가 더 많은 기능을 제공합니다. CloudWatch Events 또는 EventBridge에서 변경한 내용은 각 콘솔에 나타납니다.

이벤트는 규칙으로 구성됩니다. 규칙은 다음을 선택하여 구성됩니다.
+ **이벤트 패턴.** 각 규칙은 모니터링할 이벤트의 소스 및 유형, 이벤트 대상이 포함된 이벤트 패턴으로 표현됩니다. 이벤트를 모니터링하려면 CodePipeline과 같이 모니터링 중인 서비스를 이벤트 소스로 사용하여 규칙을 생성합니다. 예를 들어, 파이프라인, 단계 또는 작업의 상태가 변경될 때 CodePipeline을 이벤트 소스로 사용하여 규칙을 트리거하는 이벤트 패턴이 포함된 규칙을 만들 수 있습니다.
+ **대상.** 새 규칙은 선택한 서비스를 이벤트 대상으로 수신합니다. 알림을 보내거나, 상태 정보를 캡처하거나, 교정 작업을 수행하거나, 이벤트를 시작하거나, 기타 작업을 수행하도록 대상 서비스를 설정할 수 있습니다. 대상을 추가할 때 EventBridge에 선택한 대상 서비스를 호출할 수 있는 권한을 EventBridge에 부여해야 합니다.

각 실행 상태 변경 이벤트 유형은 특정 메시지 내용이 포함된 알림을 내보냅니다. 여기에서:
+ 첫 `version` 항목은 이벤트의 버전 번호를 보여 줍니다.
+ 파이프라인 `version` 아래의 `detail` 항목은 파이프라인 구조 버전 번호를 보여 줍니다.
+ 파이프라인 `execution-id` 아래의 `detail` 항목은 상태 변경을 발생시킨 파이프라인 실행의 실행 ID를 보여 줍니다. [AWS CodePipeline API 참조](https://docs.aws.amazon.com/codepipeline/latest/APIReference/)의 **GetPipelineExecution** API 직접 호출을 참조하세요.
+ `pipeline-execution-attempt` 항목은 특정 실행 ID에 대한 시도 또는 재시도 횟수를 보여줍니다.

CodePipeline은 AWS 계정 의 리소스 상태가 변경될 때마다 EventBridge에 이벤트를 보고합니다. 다음 리소스에 대해 적어도 한 번은 보장된 방식으로 이벤트가 발생합니다.
+ 파이프라인 실행
+ 단계 실행
+ 작업 실행

이벤트는 EventBridge에서 위에 설명된 이벤트 패턴 및 스키마를 사용하여 발생됩니다. 개발자 도구 콘솔에서 구성한 알림을 통해 받는 이벤트와 같이 처리된 이벤트의 경우 이벤트 메시지에는 일부 변형이 있는 이벤트 패턴 필드가 포함됩니다. 예를 들어, `detail-type` 필드는 `detailType`으로 변환됩니다. 자세한 내용은 [Amazon EventBridge API 참조](https://docs.aws.amazon.com/eventbridge/latest/APIReference/)의 **PutEvents** API 직접 호출을 참조하세요.

다음은 CodePipeline 이벤트의 예제입니다. 가능한 경우, 각 예제는 처리된 이벤트에 대한 스키마와 함께 생성된 이벤트의 스키마를 보여줍니다.

**Topics**
+ [세부 정보 유형](#detect-state-events-types)
+ [파이프라인 수준 이벤트](#detect-state-events-pipeline)
+ [단계 수준 이벤트](#detect-state-events-stage)
+ [작업 수준 이벤트](#detect-state-events-action)
+ [파이프라인 이벤트에 알림을 보내는 규칙 생성](#create-cloudwatch-notifications)

## 세부 정보 유형
<a name="detect-state-events-types"></a>

모니터링할 이벤트를 설정할 때 이벤트의 세부 유형을 선택할 수 있습니다.

다음의 상태가 변경될 때 보낼 알림을 구성할 수 있습니다.
+ 지정된 파이프라인 또는 모든 파이프라인. `"detail-type":` `"CodePipeline Pipeline Execution State Change"`를 사용하여 이를 제어합니다.
+ 지정된 파이프라인 또는 모든 파이프라인 내의 지정된 단계 또는 모든 단계. `"detail-type":` `"CodePipeline Stage Execution State Change"`를 사용하여 이를 제어합니다.
+ 지정된 파이프라인 또는 모든 파이프라인 내의 지정된 단계 또는 모든 단계에 속한 지정된 작업 또는 모든 작업. `"detail-type":` `"CodePipeline Action Execution State Change"`를 사용하여 이를 제어합니다.

**참고**  
EventBridge에서 발생하는 이벤트는 이벤트가 처리될 때 `detailType`으로 변환되는 `detail-type` 파라미터를 포함합니다.


****  


- **CodePipeline 파이프라인 실행 상태 변경**
  - **State:** CANCELED / **설명:** 파이프라인 구조가 업데이트되지 않아 파이프라인 실행이 취소되었습니다.
  - **State:** FAILED / **설명:** 파이프라인 실행이 성공적으로 완료되지 않았습니다.
  - **State:** RESUMED / **설명:** 실패한 파이프라인 실행이 RetryStageExecution API 호출에 대한 응답으로 다시 시도되었습니다.
  - **State:** STARTED / **설명:** 파이프라인 실행이 현재 실행 중입니다.
  - **State:** STOPPED / **설명:** 중지 중인 프로세스가 완료되고 파이프라인 실행이 중지됩니다.
  - **State:** 중지 중(STOPPING) / **설명:** 파이프라인 실행을 중지하고 대기하거나 중지하고 중단하라는 요청으로 인해 파이프라인 실행이 중지되는 중입니다.
  - **State:** SUCCEEDED / **설명:** 파이프라인 실행이 성공적으로 완료되었습니다.
  - **State:** SUPERSEDED / **설명:** 이 파이프라인 실행이 다음 단계가 완료되기를 기다리는 동안 새로운 파이프라인 실행이 진행되고 해당 파이프라인에서 계속되었습니다.

- **CodePipeline 단계 실행 상태 변경**
  - **State:** CANCELED / **설명:** 파이프라인 구조가 업데이트되지 않아 단계가 취소되었습니다.
  - **State:** FAILED / **설명:** 단계가 성공적으로 완료되지 않았습니다.
  - **State:** RESUMED / **설명:** 실패한 단계가 RetryStageExecution API 호출에 대한 응답으로 다시 시도되었습니다.
  - **State:** STARTED / **설명:** 단계가 현재 실행 중입니다.
  - **State:** STOPPED / **설명:** 중지 중인 프로세스가 완료되고 단계 실행이 중지됩니다.
  - **State:** 중지 중(STOPPING) / **설명:** 파이프라인 실행을 중지하고 대기하거나 중지하고 중단하라는 요청으로 인해 단계 실행이 중지되는 중입니다.
  - **State:** SUCCEEDED / **설명:** 단계가 성공적으로 완료되었습니다.

- **CodePipeline 작업 실행 상태 변경**
  - **State:** ABANDONED / **설명:** 파이프라인 실행을 중지하고 중단하라는 요청으로 인해 작업이 중단됩니다.
  - **State:** CANCELED / **설명:** 파이프라인 구조가 업데이트되지 않아 작업이 취소되었습니다.
  - **State:** FAILED / **설명:** 승인 작업의 경우 FAILED 상태는 검토자가 작업을 거부했거나 잘못된 작업 구성으로 인해 작업이 실패했음을 의미합니다.
  - **State:** STARTED / **설명:** 작업이 현재 실행 중입니다.
  - **State:** SUCCEEDED / **설명:** 작업이 성공적으로 완료되었습니다.



## 파이프라인 수준 이벤트
<a name="detect-state-events-pipeline"></a>

파이프라인 수준 이벤트는 파이프라인 실행의 상태가 변경될 때 발생합니다.

**Topics**
+ [파이프라인 STARTED 이벤트](#detect-state-events-pipeline-started)
+ [파이프라인 STOPPING 이벤트](#detect-state-events-pipeline-stopping)
+ [파이프라인 SUCCEEDED 이벤트](#detect-state-events-pipeline-succeeded)
+ [파이프라인 SUCCEEDED(Git 태그를 사용한 예제)](#w2aac42c13c29c15)
+ [파이프라인 FAILED 이벤트](#detect-state-events-pipeline-failed)
+ [파이프라인 FAILED(Git 태그를 사용한 예제)](#w2aac42c13c29c23)

### 파이프라인 STARTED 이벤트
<a name="detect-state-events-pipeline-started"></a>

 파이프라인 실행이 시작되면 다음 내용이 포함된 알림을 보내는 이벤트를 내보냅니다. 이는 `us-east-1` 리전의 `"myPipeline"`이라는 파이프라인에 대한 예제입니다. `id` 필드는 이벤트 ID를 나타내고 `account` 필드는 파이프라인이 생성된 계정 ID를 나타냅니다.

------
#### [ Emitted event ]

```
{
    "version": "0",
    "id": "01234567-EXAMPLE",
    "detail-type": "CodePipeline Pipeline Execution State Change",
    "source": "aws.codepipeline",
    "account": "123456789012",
    "time": "2020-01-24T22:03:07Z",
    "region": "us-east-1",
    "resources": [
        "arn:aws:codepipeline:us-east-1:123456789012:myPipeline"
    ],
    "detail": {
        "pipeline": "myPipeline",
        "execution-id": "12345678-1234-5678-abcd-12345678abcd",
        "start-time": "2023-10-26T13:49:39.208Z",
        "execution-trigger": {
            "trigger-type": "StartPipelineExecution",
            "trigger-detail": "arn:aws:sts::123456789012:assumed-role/Admin/my-user"
        },
        "state": "STARTED",
        "version": 1.0,
        "pipeline-execution-attempt": 1.0
    }
}
```

------
#### [ Processed event ]

```
{
    "account": "123456789012",
    "detailType": "CodePipeline Pipeline Execution State Change",
    "region": "us-east-1",
    "source": "aws.codepipeline",
    "time": "2021-06-24T00:44:50Z",
    "notificationRuleArn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/a69c62c21EXAMPLE",
    "detail": {
        "pipeline": "myPipeline",
        "execution-id": "12345678-1234-5678-abcd-12345678abcd",
        "start-time": "2023-10-26T13:49:39.208Z",
        "execution-trigger": {
            "trigger-type": "StartPipelineExecution",
            "trigger-detail": "arn:aws:sts::123456789012:assumed-role/Admin/my-user"
        },
        "state": "STARTED",
        "version": 1.0,
        "pipeline-execution-attempt": 1.0
    },
    "resources": [
        "arn:aws:codepipeline:us-east-1:123456789012:myPipeline"
    ],
    "additionalAttributes": {}
}
```

------

### 파이프라인 STOPPING 이벤트
<a name="detect-state-events-pipeline-stopping"></a>

파이프라인 실행이 중지되면 다음 내용이 포함된 알림을 보내는 이벤트를 내보냅니다. 이는 `us-west-2` 리전의 `myPipeline`이라는 파이프라인에 대한 예제입니다.

```
{
    "version": "0",
    "id": "01234567-EXAMPLE",
    "detail-type": "CodePipeline Pipeline Execution State Change",
    "source": "aws.codepipeline",
    "account": "123456789012",
    "time": "2020-01-24T22:02:20Z",
    "region": "us-west-2",
    "resources": [
        "arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
    ],
    "detail": {
        "pipeline": "myPipeline",
        "execution-id": "12345678-1234-5678-abcd-12345678abcd",
        "start-time": "2023-10-26T13:49:39.208Z",
        "state": "STOPPING",
        "version": 3.0,
        "pipeline-execution-attempt": 1.0
        "stop-execution-comments": "Stopping the pipeline for an update"
    }
}
```

### 파이프라인 SUCCEEDED 이벤트
<a name="detect-state-events-pipeline-succeeded"></a>

 파이프라인 실행이 성공하면 다음 내용이 포함된 알림을 보내는 이벤트를 내보냅니다. 이는 `us-east-1` 리전의 `myPipeline`이라는 파이프라인에 대한 예제입니다.

------
#### [ Emitted event ]

```
{
    "version": "0",
    "id": "01234567-EXAMPLE",
    "detail-type": "CodePipeline Pipeline Execution State Change",
    "source": "aws.codepipeline",
    "account": "123456789012",
    "time": "2020-01-24T22:03:44Z",
    "region": "us-east-1",
    "resources": [
        "arn:aws:codepipeline:us-east-1:123456789012:myPipeline"
    ],
    "detail": {
        "pipeline": "myPipeline",
        "execution-id": "12345678-1234-5678-abcd-12345678abcd",
        "start-time": "2023-10-26T13:49:39.208Z",
        "state": "SUCCEEDED",
        "version": 3.0,
        "pipeline-execution-attempt": 1.0
    }
}
```

------
#### [ Processed event ]

```
{
    "account": "123456789012",
    "detailType": "CodePipeline Pipeline Execution State Change",
    "region": "us-east-1",
    "source": "aws.codepipeline",
    "time": "2021-06-30T22:13:51Z",
    "notificationRuleArn": "arn:aws:codestar-notifications:us-west-2:123456789012:notificationrule/a69c62c21EXAMPLE",
    "detail": {
        "pipeline": "myPipeline",
        "execution-id": "12345678-1234-5678-abcd-12345678abcd",
        "start-time": "2023-10-26T13:49:39.208Z",
        "state": "SUCCEEDED",
        "version": 1.0,
        "pipeline-execution-attempt": 1.0
    },
    "resources": [
        "arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
    ],
    "additionalAttributes": {}
}
```

------

### 파이프라인 SUCCEEDED(Git 태그를 사용한 예제)
<a name="w2aac42c13c29c15"></a>

파이프라인 실행에 재시도하여 성공한 단계가 있으면 다음 내용이 포함된 알림을 보내는 이벤트를 내보냅니다. 이 예제는`execution-trigger`가 Git 태그에 대해 구성된 `eu-central-1` 리전에서 `myPipeline`이라는 파이프라인에 대한 것입니다.

**참고**  
`execution-trigger` 필드에는 파이프라인을 트리거한 이벤트의 종류에 따라 `tag-name` 또는 `branch-name` 둘 중 하나가 있습니다.

```
{
    "version": "0",
    "id": "b128b002-09fd-4574-4eba-27152726c777",
    "detail-type": "CodePipeline Pipeline Execution State Change",
    "source": "aws.codepipeline",
    "account": "123456789012",
    "time": "2023-10-26T13:50:53Z",
    "region": "eu-central-1",
    "resources": [
        "arn:aws:codepipeline:eu-central-1:123456789012:BuildFromTag"
    ],
    "detail": {
        "pipeline": "BuildFromTag",
        "execution-id": "e17b5773-cc0d-4db2-9ad7-594c73888de8",
        "start-time": "2023-10-26T13:49:39.208Z",
        "execution-trigger": {
            "author-display-name": "Mary Major",
            "full-repository-name": "mmajor/sample-project",
            "provider-type": "GitLab",
            "author-email": "email_address",
            "commit-message": "Update file README.md",
            "author-date": "2023-08-16T21:08:08Z",
            "tag-name": "gitlab-v4.2.1",
            "commit-id": "{{commit_ID}}",
            "connection-arn": "arn:aws:codestar-connections:eu-central-1:123456789012:connection/0f5b706a-1a1d-46c5-86b6-f177321bcfb2",
            "author-id": "Mary Major"
        },
        "state": "SUCCEEDED",
        "version": 32.0,
        "pipeline-execution-attempt": 1.0
    }
}
```

### 파이프라인 FAILED 이벤트
<a name="detect-state-events-pipeline-failed"></a>

파이프라인 실행이 실패하면 다음 내용이 포함된 알림을 보내는 이벤트를 내보냅니다. 이는 `us-west-2` 리전의 `"myPipeline"`이라는 파이프라인에 대한 예제입니다.

------
#### [ Emitted event ]

```
{
    "version": "0",
    "id": "01234567-EXAMPLE",
    "detail-type": "CodePipeline Pipeline Execution State Change",
    "source": "aws.codepipeline",
    "account": "123456789012",
    "time": "2020-01-31T18:55:43Z",
    "region": "us-west-2",
    "resources": [
        "arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
    ],
    "detail": {
        "pipeline": "myPipeline",
        "execution-id": "12345678-1234-5678-abcd-12345678abcd",
        "start-time": "2023-10-26T13:49:39.208Z",
        "state": "FAILED",
        "version": 4.0,
        "pipeline-execution-attempt": 1.0
    }
}
```

------
#### [ Processed event ]

```
{
    "account": "123456789012",
    "detailType": "CodePipeline Pipeline Execution State Change",
    "region": "us-west-2",
    "source": "aws.codepipeline",
    "time": "2021-06-24T00:46:16Z",
    "notificationRuleArn": "arn:aws:codestar-notifications:us-west-2:123456789012:notificationrule/a69c62c21EXAMPLE",
    "detail": {
        "pipeline": "myPipeline",
        "execution-id": "12345678-1234-5678-abcd-12345678abcd",
        "start-time": "2023-10-26T13:49:39.208Z",
        "state": "FAILED",
        "version": 1.0,
        "pipeline-execution-attempt": 1.0
    },
    "resources": [
        "arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
    ],
    "additionalAttributes": {
        "failedActionCount": 1,
        "failedActions": [
            {
                "action": "Deploy",
                "additionalInformation": "Deployment <ID> failed"
            }
        ],
        "failedStage": "Deploy"
    }
```

------

### 파이프라인 FAILED(Git 태그를 사용한 예제)
<a name="w2aac42c13c29c23"></a>

소스 단계에서 실패하지 않는 한 트리거가 포함된 파이프라인 구성의 경우 다음 내용이 포함된 알림을 보내는 이벤트가 발생합니다. 이 예제는`execution-trigger`가 Git 태그에 대해 구성된 `eu-central-1` 리전에서 `myPipeline`이라는 파이프라인에 대한 것입니다.

**참고**  
`execution-trigger` 필드에는 파이프라인을 트리거한 이벤트의 종류에 따라 `tag-name` 또는 `branch-name` 둘 중 하나가 있습니다.

------
#### [ Emitted event ]

```
{
    "version": "0",
    "id": "01234567-EXAMPLE",
    "detail-type": "CodePipeline Pipeline Execution State Change",
    "source": "aws.codepipeline",
    "account": "123456789012",
    "time": "2020-01-31T18:55:43Z",
    "region": "us-west-2",
    "resources": [
        "arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
    ],
    "detail": {
        "pipeline": "myPipeline",
        "execution-id": "12345678-1234-5678-abcd-12345678abcd",
        "start-time": "2023-10-26T13:49:39.208Z",
        "execution-trigger": {
            "author-display-name": "Mary Major",
            "full-repository-name": "mmajor/sample-project",
            "provider-type": "GitLab",
            "author-email": "email_address",
            "commit-message": "Update file README.md",
            "author-date": "2023-08-16T21:08:08Z",
            "tag-name": "gitlab-v4.2.1",
            "commit-id": "{{commit_ID}}",
            "connection-arn": "arn:aws:codestar-connections:eu-central-1:123456789012:connection/0f5b706a-1a1d-46c5-86b6-f177321bcfb2",
            "author-id": "Mary Major"
        },
        "state": "FAILED",
        "version": 4.0,
        "pipeline-execution-attempt": 1.0
    }
}
```

------
#### [ Processed event ]

```
{
    "account": "123456789012",
    "detailType": "CodePipeline Pipeline Execution State Change",
    "region": "us-west-2",
    "source": "aws.codepipeline",
    "time": "2021-06-24T00:46:16Z",
    "notificationRuleArn": "arn:aws:codestar-notifications:us-west-2:123456789012:notificationrule/a69c62c21EXAMPLE",
    "detail": {
        "pipeline": "myPipeline",
        "execution-id": "12345678-1234-5678-abcd-12345678abcd",
        "start-time": "2023-10-26T13:49:39.208Z",
        "execution-trigger": {
            "author-display-name": "Mary Major",
            "full-repository-name": "mmajor/sample-project",
            "provider-type": "GitLab",
            "author-email": "email_address",
            "commit-message": "Update file README.md",
            "author-date": "2023-08-16T21:08:08Z",
            "tag-name": "gitlab-v4.2.1",
            "commit-id": "{{commit_ID}}",
            "connection-arn": "arn:aws:codestar-connections:eu-central-1:123456789012:connection/0f5b706a-1a1d-46c5-86b6-f177321bcfb2",
            "author-id": "Mary Major"
        },
        "state": "FAILED",
        "version": 1.0,
        "pipeline-execution-attempt": 1.0
    },
    "resources": [
        "arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
    ],
    "additionalAttributes": {
        "failedActionCount": 1,
        "failedActions": [
            {
                "action": "Deploy",
                "additionalInformation": "Deployment <ID> failed"
            }
        ],
        "failedStage": "Deploy"
    }
```

------

## 단계 수준 이벤트
<a name="detect-state-events-stage"></a>

단계 수준 이벤트는 단계 실행의 상태가 변경될 때 발생합니다.

**Topics**
+ [단계 STARTED 이벤트](#detect-state-events-stage-started)
+ [단계 STOPPING 이벤트](#detect-state-events-stage-stopping)
+ [단계 STOPPED 이벤트](#detect-state-events-stage-stopped)
+ [단계 재시도 이벤트 이후 Stage RESUMED](#w2aac42c13c31c15)

### 단계 STARTED 이벤트
<a name="detect-state-events-stage-started"></a>

단계 실행이 시작되면 다음 내용이 포함된 알림을 보내는 이벤트를 내보냅니다. 이는 `us-east-1` 리전의 `"myPipeline"`이라는 파이프라인의 단계 `Prod`에 대한 예제입니다.

------
#### [ Emitted event ]

```
{
    "version": "0",
    "id": 01234567-EXAMPLE,
    "detail-type": "CodePipeline Stage Execution State Change",
    "source": "aws.codepipeline",
    "account": 123456789012,
    "time": "2020-01-24T22:03:07Z",
    "region": "us-east-1",
    "resources": [
        "arn:aws:codepipeline:us-east-1:123456789012:myPipeline"
    ],
    "detail": {
        "pipeline": "myPipeline",
        "version": 1.0,
        "execution-id": 12345678-1234-5678-abcd-12345678abcd,
        "start-time": "2023-10-26T13:49:39.208Z",
        "stage": "Prod",
        "state": "STARTED",
        "pipeline-execution-attempt": 1.0
    }
}
```

------
#### [ Processed event ]

```
{
    "account": "123456789012",
    "detailType": "CodePipeline Stage Execution State Change",
    "region": "us-east-1",
    "source": "aws.codepipeline",
    "time": "2021-06-24T00:45:40Z",
    "notificationRuleArn": "arn:aws:codestar-notifications:us-west-2:123456789012:notificationrule/a69c62c21EXAMPLE",
    "detail": {
        "pipeline": "myPipeline",
        "execution-id": "12345678-1234-5678-abcd-12345678abcd",
        "start-time": "2023-10-26T13:49:39.208Z",
        "stage": "Source",
        "state": "STARTED",
        "version": 1.0,
        "pipeline-execution-attempt": 0.0
    },
    "resources": [
        "arn:aws:codepipeline:us-east-1:123456789012:myPipeline"
    ],
    "additionalAttributes": {
        "sourceActions": [
            {
                "sourceActionName": "Source",
                "sourceActionProvider": "CodeCommit",
                "sourceActionVariables": {
                    "BranchName": "main",
                    "CommitId": "<ID>",
                    "RepositoryName": "my-repo"
                }
            }
        ]
    }
}
```

------

### 단계 STOPPING 이벤트
<a name="detect-state-events-stage-stopping"></a>

단계 실행이 중지되면 다음 내용이 포함된 알림을 보내는 이벤트를 내보냅니다. 이는 `us-west-2` 리전의 `myPipeline`이라는 파이프라인의 단계 `Deploy`에 대한 예제입니다.

```
{
    "version": "0",
    "id": "01234567-EXAMPLE",
    "detail-type": "CodePipeline Stage Execution State Change",
    "source": "aws.codepipeline",
    "account": "123456789012",
    "time": "2020-01-24T22:02:20Z",
    "region": "us-west-2",
    "resources": [
        "arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
    ],
    "detail": {
        "pipeline": "myPipeline",
        "execution-id": "12345678-1234-5678-abcd-12345678abcd",
        "start-time": "2023-10-26T13:49:39.208Z",
        "stage": "Deploy",
        "state": "STOPPING",
        "version": 3.0,
        "pipeline-execution-attempt": 1.0
    }
}
```

### 단계 STOPPED 이벤트
<a name="detect-state-events-stage-stopped"></a>

단계 실행이 중단되면 다음 내용이 포함된 알림을 보내는 이벤트를 내보냅니다. 이는 `us-west-2` 리전의 `myPipeline`이라는 파이프라인의 단계 `Deploy`에 대한 예제입니다.

```
{
    "version": "0",
    "id": "01234567-EXAMPLE",
    "detail-type": "CodePipeline Stage Execution State Change",
    "source": "aws.codepipeline",
    "account": "123456789012",
    "time": "2020-01-31T18:21:39Z",
    "region": "us-west-2",
    "resources": [
        "arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
    ],
    "detail": {
        "pipeline": "myPipeline",
        "execution-id": "12345678-1234-5678-abcd-12345678abcd",
        "start-time": "2023-10-26T13:49:39.208Z",
        "stage": "Deploy",
        "state": "STOPPED",
        "version": 3.0,
        "pipeline-execution-attempt": 1.0
    }
}
```

### 단계 재시도 이벤트 이후 Stage RESUMED
<a name="w2aac42c13c31c15"></a>

단계 실행이 재개되고 재시도된 단계가 있으면 다음 내용이 포함된 알림을 보내는 이벤트를 내보냅니다.

단계가 재시도되면 예제와 같이 `stage-last-retry-attempt-time` 필드가 표시됩니다. 재시도가 수행된 경우 모든 단계 이벤트에 필드가 표시됩니다.

**참고**  
단계가 재시도되면 모든 후속 단계 이벤트에 `stage-last-retry-attempt-time` 필드가 표시됩니다.

```
{
    "version": "0",
    "id": "38656bcd-a798-5f92-c738-02a71be484e1",
    "detail-type": "CodePipeline Stage Execution State Change",
    "source": "aws.codepipeline",
    "account": "123456789012",
    "time": "2023-10-26T14:14:56Z",
    "region": "eu-central-1",
    "resources": [
        "arn:aws:codepipeline:eu-central-1:123456789012:BuildFromTag"
    ],
    "detail": {
        "pipeline": "BuildFromTag",
        "execution-id": "05dafb6a-5a56-4951-a858-968795364846",
        "stage-last-retry-attempt-time": "2023-10-26T14:14:56.305Z",
        "stage": "Build",
        "state": "RESUMED",
        "version": 32.0,
        "pipeline-execution-attempt": 2.0
    }
}
```

## 작업 수준 이벤트
<a name="detect-state-events-action"></a>

작업 수준 이벤트는 작업 실행의 상태가 변경될 때 발생합니다.

**Topics**
+ [작업 STARTED 이벤트](#detect-state-events-action-started)
+ [작업 SUCCEEDED 이벤트](#detect-state-events-action-succeeded)
+ [작업 FAILED 이벤트](#detect-state-events-action-failed)
+ [작업 ABANDONED 이벤트](#detect-state-events-action-abandoned)

### 작업 STARTED 이벤트
<a name="detect-state-events-action-started"></a>

작업 실행이 시작되면 다음 내용이 포함된 알림을 보내는 이벤트를 내보냅니다. 이는 `us-east-1` 리전의 `myPipeline`이라는 파이프라인의 배포 작업 `myAction`에 대한 예제입니다.

------
#### [ Emitted event ]

```
{
    "version": "0",
    "id": 01234567-EXAMPLE,
    "detail-type": "CodePipeline Action Execution State Change",
    "source": "aws.codepipeline",
    "account": 123456789012,
    "time": "2020-01-24T22:03:07Z",
    "region": "us-east-1",
    "resources": [
        "arn:aws:codepipeline:us-east-1:123456789012:myPipeline"
    ],
    "detail": {
        "pipeline": "myPipeline",
        "execution-id": 12345678-1234-5678-abcd-12345678abcd,
        "start-time": "2023-10-26T13:51:09.981Z",
        "stage": "Prod",
        "action-execution-id": "47f821c5-a902-44b2-ae61-b878d31ecd21",
        "action": "myAction",
        "state": "STARTED",
        "type": {
            "owner": "AWS",
            "category": "Deploy",
            "provider": "CodeDeploy",
            "version": "1"
        },
        "version": 2.0
        "pipeline-execution-attempt": 1.0
        "input-artifacts": [
            {
                "name": "SourceArtifact",
                "s3location": {
                    "bucket": "codepipeline-us-east-1-BUCKETEXAMPLE",
                    "key": "myPipeline/SourceArti/KEYEXAMPLE"
                }
            }
        ]
    }
}
```

------
#### [ Processed event ]

```
{
    "account": "123456789012",
    "detailType": "CodePipeline Action Execution State Change",
    "region": "us-west-2",
    "source": "aws.codepipeline",
    "time": "2021-06-24T00:45:44Z",
    "notificationRuleArn": "arn:aws:codestar-notifications:us-west-2:123456789012:notificationrule/a69c62c21EXAMPLE",
    "detail": {
        "pipeline": "myPipeline",
        "execution-id": "12345678-1234-5678-abcd-12345678abcd",
        "start-time": "2023-10-26T13:51:09.981Z",
        "stage": "Deploy",
        "action-execution-id": "47f821c5-a902-44b2-ae61-b878d31ecd21",
        "action": "Deploy",
        "input-artifacts": [
            {
                "name": "SourceArtifact",
                "s3location": {
                    "bucket": "codepipeline-us-east-1-EXAMPLE",
                    "key": "myPipeline/SourceArti/EXAMPLE"
                }
            }
        ],
        "state": "STARTED",
        "region": "us-east-1",
        "type": {
            "owner": "AWS",
            "provider": "CodeDeploy",
            "category": "Deploy",
            "version": "1"
        },
        "version": 1.0,
        "pipeline-execution-attempt": 1.0
    },
    "resources": [
        "arn:aws:codepipeline:us-east-1:123456789012:myPipeline"
    ],
    "additionalAttributes": {}
}
```

------

### 작업 SUCCEEDED 이벤트
<a name="detect-state-events-action-succeeded"></a>

작업 실행이 성공하면 다음 내용이 포함된 알림을 보내는 이벤트를 내보냅니다. 이는 `us-west-2` 리전의 `"myPipeline"`이라는 파이프라인의 소스 작업 `"Source"`에 대한 예제입니다. 이 이벤트 유형에는 두 개의 다른 `region` 필드가 있습니다. 이벤트 `region` 필드는 파이프라인 이벤트의 리전을 지정합니다. `detail` 섹션 아래의 `region` 필드는 작업의 리전을 지정합니다.

------
#### [ Emitted event ]

```
{
    "version": "0",
    "id": "01234567-EXAMPLE",
    "detail-type": "CodePipeline Action Execution State Change",
    "source": "aws.codepipeline",
    "account": "123456789012",
    "time": "2020-01-24T22:03:11Z",
    "region": "us-west-2",
    "resources": [
        "arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
    ],
    "detail": {
        "pipeline": "myPipeline",
        "execution-id": "12345678-1234-5678-abcd-12345678abcd",
        "start-time": "2023-10-26T13:51:09.981Z",
        "stage": "Source",
        "execution-result": {
            "external-execution-url": "https://us-west-2.console.aws.amazon.com/codecommit/home#/repository/my-repo/commit/8cf40f2EXAMPLE",
            "external-execution-summary": "Added LICENSE.txt",
            "external-execution-id": "8cf40fEXAMPLE"
        },
        "output-artifacts": [
            {
                "name": "SourceArtifact",
                "s3location": {
                    "bucket": "codepipeline-us-west-2-BUCKETEXAMPLE",
                    "key": "myPipeline/SourceArti/KEYEXAMPLE"
                }
            }
        ],
        "action-execution-id": "47f821c5-a902-44b2-ae61-b878d31ecd21",
        "action": "Source",
        "state": "SUCCEEDED",
        "region": "us-west-2",
        "type": {
            "owner": "AWS",
            "provider": "CodeCommit",
            "category": "Source",
            "version": "1"
        },
        "version": 3.0,
        "pipeline-execution-attempt": 1.0
    }
}
```

------
#### [ Processed event ]

```
{
    "account": "123456789012",
    "detailType": "CodePipeline Action Execution State Change",
    "region": "us-west-2",
    "source": "aws.codepipeline",
    "time": "2021-06-24T00:45:44Z",
    "notificationRuleArn": "arn:aws:codestar-notifications:us-west-2:ACCOUNT:notificationrule/a69c62c21EXAMPLE",
    "detail": {
        "pipeline": "myPipeline",
        "execution-id": "arn:aws:codepipeline:us-west-2:123456789012:myPipeline",
        "start-time": "2023-10-26T13:51:09.981Z",
        "stage": "Source",
        "execution-result": {
            "external-execution-url": "https://us-west-2.console.aws.amazon.com/codecommit/home#/repository/my-repo/commit/8cf40f2EXAMPLE",
            "external-execution-summary": "Edited index.html",
            "external-execution-id": "36ab3ab7EXAMPLE"
        },
        "output-artifacts": [
            {
                "name": "SourceArtifact",
                "s3location": {
                    "bucket": "codepipeline-us-west-2-EXAMPLE",
                    "key": "myPipeline/SourceArti/EXAMPLE"
                }
            }
        ],
        "action-execution-id": "47f821c5-a902-44b2-ae61-b878d31ecd21",
        "action": "Source",
        "state": "SUCCEEDED",
        "region": "us-west-2",
        "type": {
            "owner": "AWS",
            "provider": "CodeCommit",
            "category": "Source",
            "version": "1"
        },
        "version": 1.0,
        "pipeline-execution-attempt": 1.0
    },
    "resources": [
        "arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
    ],
    "additionalAttributes": {}
}
```

------

### 작업 FAILED 이벤트
<a name="detect-state-events-action-failed"></a>

작업 실행이 실패하면 다음 내용이 포함된 알림을 보내는 이벤트를 내보냅니다. 이는 `us-west-2` 리전의 `"myPipeline"`이라는 파이프라인의 작업 `"Deploy"`에 대한 예제입니다.

------
#### [ Emitted event ]

```
{
    "version": "0",
    "id": "01234567-EXAMPLE",
    "detail-type": "CodePipeline Action Execution State Change",
    "source": "aws.codepipeline",
    "account": "123456789012",
    "time": "2020-01-31T18:55:43Z",
    "region": "us-west-2",
    "resources": [
        "arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
    ],
    "detail": {
        "pipeline": "myPipeline",
        "execution-id": "12345678-1234-5678-abcd-12345678abcd", 
        "start-time": "2023-10-26T13:51:09.981Z",
        "stage": "Deploy",
        "execution-result": {
            "external-execution-url": "https://us-west-2.console.aws.amazon.com/codedeploy/home?#/deployments/<ID>",
            "external-execution-summary": "Deployment <ID> failed",
            "external-execution-id": "<ID>",
            "error-code": "JobFailed"
        },
        "action-execution-id": "47f821c5-a902-44b2-ae61-b878d31ecd21",
        "action": "Deploy",
        "state": "FAILED",
        "region": "us-west-2",
        "type": {
            "owner": "AWS",
            "provider": "CodeDeploy",
            "category": "Deploy",
            "version": "1"
        },
        "version": 4.0,
        "pipeline-execution-attempt": 1.0
    }
}
```

------
#### [ Processed event ]

```
{
    "account": "123456789012",
    "detailType": "CodePipeline Action Execution State Change",
    "region": "us-west-2",
    "source": "aws.codepipeline",
    "time": "2021-06-24T00:46:16Z",
    "notificationRuleArn": "arn:aws:codestar-notifications:us-west-2:123456789012:notificationrule/a69c62c21EXAMPLE",
    "detail": {
        "pipeline": "myPipeline",
        "execution-id": "12345678-1234-5678-abcd-12345678abcd",
        "stage": "Deploy",
        "execution-result": {
            "external-execution-url": "https://console.aws.amazon.com/codedeploy/home?region=us-west-2#/deployments/<ID>",
            "external-execution-summary": "Deployment <ID> failed",
            "external-execution-id": "<ID>",
            "error-code": "JobFailed"
        },  
        "action-execution-id": "47f821c5-a902-44b2-ae61-b878d31ecd21",
        "action": "Deploy",
        "state": "FAILED",
        "region": "us-west-2",
        "type": {
            "owner": "AWS",
            "provider": "CodeDeploy",
            "category": "Deploy",
            "version": "1"
        },
        "version": 13.0,
        "pipeline-execution-attempt": 1.0
    },
    "resources": [
        "arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
    ],
    "additionalAttributes": {
        "additionalInformation": "Deployment <ID> failed"
    }
}
```

------

### 작업 ABANDONED 이벤트
<a name="detect-state-events-action-abandoned"></a>

작업 실행이 중단되면 다음 내용이 포함된 알림을 보내는 이벤트를 내보냅니다. 이는 `us-west-2` 리전의 `"myPipeline"`이라는 파이프라인의 작업 `"Deploy"`에 대한 예제입니다.

```
{
    "version": "0",
    "id": "01234567-EXAMPLE",
    "detail-type": "CodePipeline Action Execution State Change",
    "source": "aws.codepipeline",
    "account": "123456789012",
    "time": "2020-01-31T18:21:39Z",
    "region": "us-west-2",
    "resources": [
        "arn:aws:codepipeline:us-west-2:123456789012:myPipeline"
    ],
    "detail": {
        "pipeline": "myPipeline",
        "execution-id": "12345678-1234-5678-abcd-12345678abcd",
        "stage": "Deploy",
        "action-execution-id": "47f821c5-a902-44b2-ae61-b878d31ecd21",
        "action": "Deploy",
        "state": "ABANDONED",
        "region": "us-west-2",
        "type": {
            "owner": "AWS",
            "provider": "CodeDeploy",
            "category": "Deploy",
            "version": "1"
        },
        "version": 3.0,
        "pipeline-execution-attempt": 1.0
    }
}
```

## 파이프라인 이벤트에 알림을 보내는 규칙 생성
<a name="create-cloudwatch-notifications"></a>

규칙은 특정 이벤트를 감시한 다음 선택한 AWS 대상으로 라우팅합니다. 다른 AWS 작업이 발생할 때 AWS 작업을 자동으로 수행하는 규칙 또는 설정된 일정에 따라 AWS 작업을 정기적으로 수행하는 규칙을 생성할 수 있습니다.

**Topics**
+ [파이프라인 상태 변경 시 알림 보내기(콘솔)](#monitoring-cloudwatch-events-console)
+ [파이프라인 상태 변경 시 알림 보내기(CLI)](#monitoring-cloudwatch-events-cli)

### 파이프라인 상태 변경 시 알림 보내기(콘솔)
<a name="monitoring-cloudwatch-events-console"></a>

다음 단계에서는 EventBridge 콘솔을 사용하여 CodePipeline의 변경에 대한 알림을 보내는 규칙을 만드는 방법을 보여 줍니다.

**Amazon S3 소스가 포함된 파이프라인을 대상으로 지정하는 EventBridge 규칙을 생성하려면**

1. [https://console.aws.amazon.com/events/](https://console.aws.amazon.com/events/)에서 Amazon EventBridge 콘솔을 엽니다.

1. 탐색 창에서 **규칙**을 선택합니다. 기본 버스를 선택된 상태로 두거나 이벤트 버스를 선택하세요. **규칙 생성**을 선택합니다.

1. **이름**에 역할의 이름을 입력합니다.

1. **규칙 유형**에서 **이벤트 패턴이 있는 규칙**을 선택합니다. **다음**을 선택합니다.

1. **이벤트 패턴**에서 **AWS 서비스**를 선택합니다.

1. [**Event Type**] 드롭다운 목록에서 알림의 상태 변경 수준을 선택합니다.
   + 파이프라인 수준 이벤트에 적용되는 규칙의 경우 [**CodePipeline Pipeline Execution State Change**]를 선택합니다.
   + 상태 수준 이벤트에 적용되는 규칙의 경우 [**CodePipeline Stage Execution State Change**]를 선택합니다.
   + 작업 수준 이벤트에 적용되는 규칙의 경우 [**CodePipeline Action Execution State Change**]를 선택합니다.

1. 규칙을 적용할 상태 변경을 지정합니다.
   + 모든 상태 변경에 적용되는 규칙의 경우 [**Any state**]를 선택합니다.
   + 일부 상태 변경에만 적용되는 규칙의 경우 [**Specific state(s)**]를 선택한 후 목록에서 상태 값을 한 개 이상 선택합니다.

1. 선택기에서 허용하는 것보다 더 자세한 이벤트 패턴의 경우 **이벤트 패턴** 창의 **패턴 편집** 옵션을 사용하여 이벤트 패턴을 JSON 형식으로 지정할 수도 있습니다.
**참고**  
달리 지정하지 않으면 모든 파이프라인/단계/작업 및 상태에 대한 이벤트 패턴이 생성됩니다.

   더 세부적인 이벤트 패턴의 경우 다음 이벤트 패턴 예제를 복사하여 **이벤트 패턴** 창에 붙여넣으면 됩니다.
   +   
**Example**  

     다음 이벤트 패턴 샘플을 사용하면 모든 파이프라인에서 실패한 배포 및 빌드 작업을 캡처합니다.

     ```
     {
     "source": [
         "aws.codepipeline"
       ],
       "detail-type": [
         "CodePipeline Action Execution State Change"
       ],
       "detail": {
         "state": [
           "FAILED"
         ],
         "type": {
           "category": ["Deploy", "Build"]
         }
       }
     }
     ```
   +   
**Example**  

     다음 이벤트 패턴 샘플을 사용하면 모든 파이프라인에서 거부되었거나 실패한 모든 승인 작업을 캡처합니다.

     ```
     {
      "source": [
         "aws.codepipeline"
       ],
       "detail-type": [
         "CodePipeline Action Execution State Change"
       ],
       "detail": {
         "state": [
           "FAILED"
         ],
         "type": {
           "category": ["Approval"]
         }
       }
     }
     ```
   +   
**Example**  

     다음 이벤트 패턴 샘플을 사용하면 지정된 파이프라인에서 모든 이벤트를 캡처합니다.

     ```
     {
     "source": [
         "aws.codepipeline"
       ],
       "detail-type": [
         "CodePipeline Pipeline Execution State Change",
         "CodePipeline Action Execution State Change",
         "CodePipeline Stage Execution State Change"
       ],
       "detail": {
         "pipeline": ["myPipeline", "my2ndPipeline"]
       }
     }
     ```

1. **다음**을 선택합니다.

1. **대상 유형**에서 **AWS 서비스**를 선택합니다.

1. **대상 선택**에서 **CodePipeline**을 선택합니다. **Pipeline ARN**에서 이 규칙에 의해 시작되는 파이프라인의 파이프라인 ARN을 입력합니다.
**참고**  
파이프라인 ARN을 확인하려면 **get-pipeline** 명령을 실행합니다. 출력에 파이프라인 ARN이 나타납니다. ARN의 형식은 다음과 같습니다.  
arn:aws:codepipeline:{{region}}:{{account}}:{{pipeline-name}}  
파이프라인 ARN 샘플:  
arn:aws:codepipeline:us-east-2:80398EXAMPLE:MyFirstPipeline 

1. EventBridge에 EventBridge 규칙과 연결된 대상을 호출할 권한을 부여하는 IAM 서비스 역할을 생성하거나 지정하려면(이 경우에는 대상이 CodePipeline): 
   + **이 특정 리소스에 대한 새 역할 생성**을 선택하여 EventBridge에 파이프라인 실행을 시작할 권한을 제공하는 서비스 역할을 생성합니다.
   + **기존 역할 사용**을 선택하여 EventBridge에 파이프라인 실행을 시작할 권한을 제공하는 서비스 역할을 입력합니다.

1. **다음**을 선택합니다.

1. **태그** 페이지에서 **다음**을 선택합니다.

1. **검토 및 생성** 페이지에서 규칙 구성을 검토합니다. 규칙이 만족스러우면 **규칙 생성(Create rule)**을 선택하세요.

### 파이프라인 상태 변경 시 알림 보내기(CLI)
<a name="monitoring-cloudwatch-events-cli"></a>

다음 단계에서는 CLI를 사용하여 CodePipeline의 변경에 대한 알림을 보내는 CloudWatch Events 규칙을 만드는 방법을 보여 줍니다.

 AWS CLI 를 사용하여 규칙을 생성하려면 다음을 지정하여 **put-rule** 명령을 호출합니다.
+ 만들려는 규칙을 고유하게 식별하는 이름. 이 이름은 AWS 계정과 관련해 CodePipeline에서 만드는 모든 파이프라인에서 고유해야 합니다.
+ 소스의 이벤트 패턴 및 규칙에서 사용하는 세부 정보 필드. 자세한 내용은 [Amazon EventBridge 및 이벤트 패턴](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-events.html)을 참조하세요.

**CodePipeline이 이벤트 소스인 EventBridge 규칙을 만들려면**

1. **put-rule** 명령을 호출하여 이벤트 패턴을 지정하는 규칙을 만듭니다. (유효한 상태는 앞의 표 참조)

   다음 명령 샘플은 **--event-pattern**을 사용하여 "myPipeline"이라는 파이프라인에 대한 파이프라인 실행이 실패하면 CloudWatch 이벤트를 내보내는 `“MyPipelineStateChanges”`라는 규칙을 만듭니다.

   ```
   aws events put-rule --name "MyPipelineStateChanges" --event-pattern "{\"source\":[\"aws.codepipeline\"],\"detail-type\":[\"CodePipeline Pipeline Execution State Change\"],\"detail\":{\"pipeline\":[\"myPipeline\"],\"state\":[\"FAILED\"]}}"
   ```

1. **put-targets** 명령을 호출하고 다음 파라미터를 포함합니다.
   + `--rule` 파라미터는 **put-rule**을 사용하여 생성한 `rule_name`에 사용됩니다.
   + `--targets` 파라미터는 대상 목록에 있는 대상의 목록 `Id` 및 Amazon SNS 주제의 `ARN`에 사용됩니다.

   다음 예제 명령은 `MyPipelineStateChanges`이라는 규칙에 대해 대상 `Id`가 숫자 1로 구성됨을 지정하며, 규칙의 대상 목록에서 1로 대상 1로 표시됩니다. 이 예제 명령은 또한 Amazon SNS 주제에 대한 예제 `ARN`을 지정합니다.

   ```
   aws events put-targets --rule MyPipelineStateChanges --targets Id=1,Arn=arn:aws:sns:us-west-2:11111EXAMPLE:MyNotificationTopic
   ```

1. 지정된 대상 서비스를 사용하여 알림을 호출할 수 있도록 EventBridge에 권한을 추가합니다. 자세한 내용은 [Amazon EventBridge에 대한 리소스 기반 정책 사용](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-use-resource-based.html)을 참조하세요.