

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# CodePipeline イベントのモニタリング
<a name="detect-state-changes-cloudwatch-events"></a>



EventBridge で CodePipeline イベントをモニタリングして、独自のアプリケーション、software-as-a-service (SaaS) アプリケーション、および からリアルタイムデータのストリームを配信できます AWS のサービス。 EventBridge EventBridge は、そのデータを AWS Lambda や Amazon Simple Notification Service などのターゲットにルーティングします。これらのイベントは、Amazon CloudWatch Events に表示されるイベントと同じで、 AWS リソースの変更を記述するシステムイベントのほぼリアルタイムのストリームを提供します。詳細については、*Amazon EventBridge ユーザーガイド*の「[What Is Amazon EventBridge?](https://docs.aws.amazon.com/eventbridge/latest/userguide/)」を参照してください。

**注記**  
イベントを管理するには、Amazon EventBridge が好ましい方法です。Amazon CloudWatch Events と EventBridge は同じ基盤となるサービスと API ですが、EventBridge はより多くの機能を提供します。CloudWatch Events または EventBridge のいずれかで行った変更は、各コンソールに表示されます。

イベントはルールで構成されています。ルールは、次のものを選択して設定します:
+ **イベントパターン。**各ルールは、モニタリングするイベントのソースとタイプ、およびイベントターゲットを含むイベントパターンとして表現されます。イベントをモニタリングするには、モニタリングするサービスを CodePipeline などのイベントソースとしてルールを作成します。例えば、パイプライン、ステージ、またはアクションの状態に変更があった場合にルールをトリガーするよう、イベントソースとして CodePipeline を使用するイベントパターンでルールを作成することが可能です。
+ **ターゲット。**新しいルールは選択したサービスをイベントターゲットとして受け取ります。ターゲットサービスを設定することで、通知を送り、状態情報を取得し、是正措置を講じ、イベントを開始し、その他のアクションを実行します。ターゲットを追加するときには、選択したターゲットサービスを呼び出すためのアクセス許可も EventBridge に付与する必要があります。

各タイプの実行の状態変更イベントは、以下の特定のメッセージ内容で通知を送信します。
+ 最初の `version` エントリは、イベントのバージョン番号を示します。
+ パイプライン `detail` の `version` エントリは、パイプライン構造のバージョン番号を示します。
+ パイプライン `detail` の `execution-id` エントリは、状態変更の原因となったパイプラインの実行 ID を示します。[[**GetPipelineExecution** API リファレンス](https://docs.aws.amazon.com/codepipeline/latest/APIReference/)] の [AWS CodePipeline API コール] を参照してください。
+ `pipeline-execution-attempt` エントリは、特定の実行 ID に対する試行回数、または再試行回数を示しています。

CodePipeline は、 AWS アカウント 内のリソースの状態が変わるたびに、EventBridge にイベントをレポートします。イベントは、以下のリソースに対して、少なくとも 1 回保証ベースで発行されます:
+ パイプライン実行
+ ステージ実行
+ アクション実行

 イベントは、上記のイベントパターンとスキーマの詳細を使用して 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 によって発行されるイベントには、`detail-type` パラメータが含まれ、イベントが処理される際に、`detailType` に変換されます。


****  
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/codepipeline/latest/userguide/detect-state-changes-cloudwatch-events.html)

## パイプラインレベルのイベント
<a name="detect-state-events-pipeline"></a>

パイプラインレベルのイベントは、パイプライン実行の状態が変更されたときに発生します。

**Topics**
+ [パイプライン開始イベント](#detect-state-events-pipeline-started)
+ [パイプライン停止イベント](#detect-state-events-pipeline-stopping)
+ [パイプライン成功イベント](#detect-state-events-pipeline-succeeded)
+ [パイプラインが成功しました (Git タグを使用した例)](#w2aac42c13c29c15)
+ [パイプライン失敗イベント](#detect-state-events-pipeline-failed)
+ [パイプラインが失敗しました (Git タグを使用した例)](#w2aac42c13c29c23)

### パイプライン開始イベント
<a name="detect-state-events-pipeline-started"></a>

 パイプライン実行が開始すると、以下の内容の通知が送信されます。この例は、`"myPipeline"` リージョンの `us-east-1` という名前のパイプラインです。`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": {}
}
```

------

### パイプライン停止イベント
<a name="detect-state-events-pipeline-stopping"></a>

パイプライン実行が停止すると、以下の内容の通知が送信されます。この例は、`myPipeline` リージョンの `us-west-2` という名前のパイプラインです。

```
{
    "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"
    }
}
```

### パイプライン成功イベント
<a name="detect-state-events-pipeline-succeeded"></a>

 パイプライン実行が成功すると、以下の内容の通知が送信されます。この例は、`myPipeline` `us-east-1` リージョンの という名前のパイプラインです。

------
#### [ 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": {}
}
```

------

### パイプラインが成功しました (Git タグを使用した例)
<a name="w2aac42c13c29c15"></a>

パイプラインの実行が再試行され、成功したステージがあると、以下の内容の通知を送信するイベントが発生します。この例は、`eu-central-1` リージョンの `myPipeline` という名前のパイプラインのもので、`execution-trigger` が Git タグに設定されています。

**注記**  
`execution-trigger`\$1 フィールドには、パイプラインをトリガーしたイベントの種類に応じて、`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
    }
}
```

### パイプライン失敗イベント
<a name="detect-state-events-pipeline-failed"></a>

パイプライン実行が成功すると、以下の内容の通知が送信されます。この例は、`"myPipeline"` リージョンの `us-west-2` という名前のパイプラインです。

------
#### [ 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"
    }
```

------

### パイプラインが失敗しました (Git タグを使用した例)
<a name="w2aac42c13c29c23"></a>

トリガーで設定されたパイプラインがソースステージで失敗しない限り、以下の内容の通知を送信するイベントが発生します。この例は、`eu-central-1` リージョンの `myPipeline` という名前のパイプラインのもので、`execution-trigger` が Git タグに設定されています。

**注記**  
`execution-trigger`\$1 フィールドには、パイプラインをトリガーしたイベントの種類に応じて、`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**
+ [ステージ開始イベント](#detect-state-events-stage-started)
+ [ステージ停止イベント](#detect-state-events-stage-stopping)
+ [ステージ停止イベント](#detect-state-events-stage-stopped)
+ [ステージ再試行後のステージ再開イベント](#w2aac42c13c31c15)

### ステージ開始イベント
<a name="detect-state-events-stage-started"></a>

ステージ実行が開始すると、以下の内容の通知が送信されます。この例は、`"myPipeline"` ステージの `us-east-1` リージョンの `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"
                }
            }
        ]
    }
}
```

------

### ステージ停止イベント
<a name="detect-state-events-stage-stopping"></a>

ステージ実行が停止すると、以下の内容の通知が送信されます。この例は、`myPipeline` ステージの `us-west-2` リージョンの `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
    }
}
```

### ステージ停止イベント
<a name="detect-state-events-stage-stopped"></a>

ステージ実行が停止すると、以下の内容の通知が送信されます。この例は、`myPipeline` ステージの `us-west-2` リージョンの `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
    }
}
```

### ステージ再試行後のステージ再開イベント
<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**
+ [アクション開始イベント](#detect-state-events-action-started)
+ [アクション成功イベント](#detect-state-events-action-succeeded)
+ [アクション失敗イベント](#detect-state-events-action-failed)
+ [アクション放棄イベント](#detect-state-events-action-abandoned)

### アクション開始イベント
<a name="detect-state-events-action-started"></a>

アクション実行が開始すると、以下の内容の通知が送信されます。この例は、デプロイアクション `myPipeline` の `us-east-1` リージョンの `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": {}
}
```

------

### アクション成功イベント
<a name="detect-state-events-action-succeeded"></a>

アクション実行が成功すると、以下の内容の通知が送信されます。この例は、ソースアクション `"myPipeline"` の `us-west-2` リージョンの `"Source"` という名前のパイプラインです。このイベントタイプには、2 つの異なる `region` フィールドがあります。イベント `region` フィールドは、パイプラインイベントのリージョンを指定します。`region` セクション下の `detail` フィールドは、アクションのリージョンを指定します。

------
#### [ 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": {}
}
```

------

### アクション失敗イベント
<a name="detect-state-events-action-failed"></a>

アクション実行が成功すると、以下の内容の通知が送信されます。この例は、`"myPipeline"` アクションの `us-west-2` リージョンの `"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"
    }
}
```

------

### アクション放棄イベント
<a name="detect-state-events-action-abandoned"></a>

アクション実行が放棄されると、以下の内容の通知が送信されます。この例は、`"myPipeline"` アクションの `us-west-2` リージョンの `"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. Amazon EventBridge コンソール ([https://console.aws.amazon.com/events/](https://console.aws.amazon.com/events/)) を開きます。

1. ナビゲーションペインで **[ルール]** を選択します。デフォルトのバスを選択したままにするか、イベントバスを選択します。**[‬ルールを作成]‭** を選択します。

1. [**名前**] で、ルールの名前を入力します。

1. [**ルールタイプ**] で、[**イベントパターンを持つルール**] を選択します。[**次へ**] を選択します。

1. **[イベントパターン]** で、**[AWS のサービス]** を選択します。

1. [**イベントタイプ**] ドロップダウンリストで、通知する状態変更のレベルを選択します。
   + パイプラインイベントに適用されるルールでは、[**CodePipeline Pipeline Execution State Change**] を選択します。
   + ステージレベルのイベントに適用されるルールでは、[**CodePipeline Stage Execution State Change**] を選択します。
   + アクションレベルのイベントに適用されるルールでは、[**CodePipeline Action Execution State Change**] を選択します。

1. ルールを適用する状態変更を指定します。
   + すべての状態変更に適用されるルールには、[**Any state**] を選択します。
   + いくつかの状態変更のみに適用されるルールには、[**Specific state(s)**] を選択してから、リストから 1 つ以上の値を選択します。

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**] を選択します。[**パイプライン ARN**] に、このルールによって開始されるパイプラインの ARN を入力します。
**注記**  
このパイプライン ARN を取得するには、**get-pipeline** コマンドを実行します。パイプライン 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** を使用して、`“MyPipelineStateChanges”` というルールを作成し、"myPipeline" という名前のパイプラインでパイプライン実行に失敗したときに CloudWatch イベントを送信します。

   ```
   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 です。このサンプルコマンドでは、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)] を参照してください。