

# AWS CLI を使用した EventBridge Pipes の例
<a name="cli_pipes_code_examples"></a>

次のコード例では、EventBridge Pipes で AWS Command Line Interface を使用してアクションを実行し、一般的なシナリオを実装する方法を示しています。

*アクション*はより大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。アクションは個々のサービス機能を呼び出す方法を示していますが、コンテキスト内のアクションは、関連するシナリオで確認できます。

各例には完全なソースコードへのリンクが含まれており、コードの設定方法と実行方法に関する手順を確認できます。

**Topics**
+ [アクション](#actions)

## アクション
<a name="actions"></a>

### `create-pipe`
<a name="pipes_CreatePipe_cli_topic"></a>

次のコード例は、`create-pipe` を使用する方法を示しています。

**AWS CLI**  
**パイプを作成するには**  
次の `create-pipe` の例では、ソースとして SQS、ターゲットとして CloudWatch Log Group を使用して、`Demo_Pipe` という名前のパイプを作成します。  

```
aws pipes create-pipe \
    --name Demo_Pipe \
    --desired-state RUNNING \
    --role-arn arn:aws:iam::123456789012:role/service-role/Amazon_EventBridge_Pipe_Demo_Pipe_28b3aa4f \
    --source arn:aws:sqs:us-east-1:123456789012:Demo_Queue \
    --target arn:aws:logs:us-east-1:123456789012:log-group:/aws/pipes/Demo_LogGroup
```
出力:  

```
{
    "Arn": "arn:aws:pipes:us-east-1:123456789012:pipe/Demo_Pipe",
    "Name": "Demo_Pipe",
    "DesiredState": "RUNNING",
    "CurrentState": "CREATING",
    "CreationTime": "2024-10-08T12:33:59-05:00",
    "LastModifiedTime": "2024-10-08T12:33:59.684839-05:00"
}
```
詳細については、*Amazon EventBridge ユーザーガイド*の「[Amazon EventBridge Pipes の概念](https://docs.aws.amazon.com/eventbridge/latest/userguide/pipes-concepts.html)」を参照してください。  
+  API の詳細については、*AWS CLI コマンドリファレンス*の「[CreatePipe](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/pipes/create-pipe.html)」を参照してください。

### `delete-pipe`
<a name="pipes_DeletePipe_cli_topic"></a>

次のコード例は、`delete-pipe` を使用する方法を示しています。

**AWS CLI**  
**既存のパイプを削除するには**  
次の `delete-pipe` の例では、指定したアカウントから `Demo_Pipe` という名前のパイプを削除します。  

```
aws pipes delete-pipe \
    --name Demo_Pipe
```
出力:  

```
{
    "Arn": "arn:aws:pipes:us-east-1:123456789012:pipe/Demo_Pipe",
    "Name": "Demo_Pipe",
    "DesiredState": "STOPPED",
    "CurrentState": "DELETING",
    "CreationTime": "2024-10-08T09:29:10-05:00",
    "LastModifiedTime": "2024-10-08T11:57:22-05:00"
}
```
詳細については、*Amazon EventBridge ユーザーガイド*の「[Amazon EventBridge Pipes の概念](https://docs.aws.amazon.com/eventbridge/latest/userguide/pipes-concepts.html)」を参照してください。  
+  API の詳細については、*AWS CLI コマンドリファレンス*の「[DeletePipe](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/pipes/delete-pipe.html)」を参照してください。

### `describe-pipe`
<a name="pipes_DescribePipe_cli_topic"></a>

次のコード例は、`describe-pipe` を使用する方法を示しています。

**AWS CLI**  
**パイプに関する情報を取得するには**  
次の `describe-pipe` の例では、指定したアカウントのパイプ `Demo_Pipe` に関する情報を表示します。  

```
aws pipes describe-pipe \
    --name Demo_Pipe
```
出力:  

```
{
    "Arn": "arn:aws:pipes:us-east-1:123456789012:pipe/Demo_Pipe",
    "Name": "Demo_Pipe",
    "DesiredState": "RUNNING",
    "CurrentState": "RUNNING",
    "StateReason": "User initiated",
    "Source": "arn:aws:sqs:us-east-1:123456789012:Demo_Queue",
    "SourceParameters": {
        "SqsQueueParameters": {
            "BatchSize": 1
        }
    },
    "EnrichmentParameters": {},
    "Target": "arn:aws:logs:us-east-1:123456789012:log-group:/aws/pipes/Demo_LogGroup",
    "TargetParameters": {},
    "RoleArn": "arn:aws:iam::123456789012:role/service-role/Amazon_EventBridge_Pipe_Demo_Pipe_28b3aa4f",
    "Tags": {},
    "CreationTime": "2024-10-08T09:29:10-05:00",
    "LastModifiedTime": "2024-10-08T10:23:47-05:00",
    "LogConfiguration": {
        "CloudwatchLogsLogDestination": {
            "LogGroupArn": "arn:aws:logs:us-east-1:123456789012:log-group:/aws/vendedlogs/pipes/Demo_Pipe"
        },
        "Level": "ERROR"
    }
}
```
詳細については、*Amazon EventBridge ユーザーガイド*の「[Amazon EventBridge Pipes の概念](https://docs.aws.amazon.com/eventbridge/latest/userguide/pipes-concepts.html)」を参照してください。  
+  API の詳細については、*AWS CLI コマンドリファレンス*の「[DescribePipe](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/pipes/describe-pipe.html)」を参照してください。

### `list-pipes`
<a name="pipes_ListPipes_cli_topic"></a>

次のコード例は、`list-pipes` を使用する方法を示しています。

**AWS CLI**  
**パイプのリストを取得するには**  
次の `list-pipes` の例では、指定したアカウントのすべてのパイプを表示します。  

```
aws pipes list-pipes
```
出力:  

```
{
    "Pipes": [
        {
            "Name": "Demo_Pipe",
            "Arn": "arn:aws:pipes:us-east-1:123456789012:pipe/Demo_Pipe",
            "DesiredState": "RUNNING",
            "CurrentState": "RUNNING",
            "StateReason": "User initiated",
            "CreationTime": "2024-10-08T09:29:10-05:00",
            "LastModifiedTime": "2024-10-08T10:23:47-05:00",
            "Source": "arn:aws:sqs:us-east-1:123456789012:Demo_Queue",
            "Target": "arn:aws:logs:us-east-1:123456789012:log-group:/aws/pipes/Demo_LogGroup"
        }
    ]
}
```
詳細については、*Amazon EventBridge ユーザーガイド*の「[Amazon EventBridge Pipes の概念](https://docs.aws.amazon.com/eventbridge/latest/userguide/pipes-concepts.html)」を参照してください。  
+  API の詳細については、*AWS CLI コマンドリファレンス*の「[ListPipes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/pipes/list-pipes.html)」を参照してください。

### `list-tags-for-resource`
<a name="pipes_ListTagsForResource_cli_topic"></a>

次のコード例は、`list-tags-for-resource` を使用する方法を示しています。

**AWS CLI**  
**既存のパイプに関連付けられているタグを一覧表示するには**  
次の `list-tags-for-resource` の例では、指定したアカウントの `Demo_Pipe` という名前のパイプに関連付けられているすべてのタグを一覧表示します。  

```
aws pipes list-tags-for-resource \
    --resource-arn arn:aws:pipes:us-east-1:123456789012:pipe/Demo_Pipe
```
出力:  

```
{
    "tags": {
        "stack": "Production",
        "team": "DevOps"
    }
}
```
詳細については、*Amazon EventBridge ユーザーガイド*の「[Amazon EventBridge Pipes の概念](https://docs.aws.amazon.com/eventbridge/latest/userguide/pipes-concepts.html)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[ListTagsForResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/pipes/list-tags-for-resource.html)」を参照してください。

### `start-pipe`
<a name="pipes_StartPipe_cli_topic"></a>

次のコード例は、`start-pipe` を使用する方法を示しています。

**AWS CLI**  
**既存のパイプを開始するには**  
次の `start-pipe` の例では、指定したアカウントの `Demo_Pipe` という名前のパイプを開始します。  

```
aws pipes start-pipe \
    --name Demo_Pipe
```
出力:  

```
{
    "Arn": "arn:aws:pipes:us-east-1:123456789012:pipe/Demo_Pipe",
    "Name": "Demo_Pipe",
    "DesiredState": "RUNNING",
    "CurrentState": "STARTING",
    "CreationTime": "2024-10-08T09:29:10-05:00",
    "LastModifiedTime": "2024-10-08T10:17:24-05:00"
}
```
詳細については、*Amazon EventBridge ユーザーガイド*の「[Amazon EventBridge パイプの開始または停止](https://docs.aws.amazon.com/eventbridge/latest/userguide/pipes-start-stop.html)」を参照してください。  
+  API の詳細については、*AWS CLI コマンドリファレンス*の「[StartPipe](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/pipes/start-pipe.html)」を参照してください。

### `stop-pipe`
<a name="pipes_StopPipe_cli_topic"></a>

次のコード例は、`stop-pipe` を使用する方法を示しています。

**AWS CLI**  
**既存のパイプを停止するには**  
次の `stop-pipe` の例では、指定したアカウントの `Demo_Pipe` という名前のパイプを停止します。  

```
aws pipes stop-pipe \
    --name Demo_Pipe
```
出力:  

```
{
    "Arn": "arn:aws:pipes:us-east-1:123456789012:pipe/Demo_Pipe",
    "Name": "Demo_Pipe",
    "DesiredState": "STOPPED",
    "CurrentState": "STOPPING",
    "CreationTime": "2024-10-08T09:29:10-05:00",
    "LastModifiedTime": "2024-10-08T09:29:49-05:00"
}
```
詳細については、*Amazon EventBridge ユーザーガイド*の「[Amazon EventBridge パイプの開始または停止](https://docs.aws.amazon.com/eventbridge/latest/userguide/pipes-start-stop.html)」を参照してください。  
+  API の詳細については、*AWS CLI コマンドリファレンス*の「[StopPipe](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/pipes/stop-pipe.html)」を参照してください。

### `tag-resource`
<a name="pipes_TagResource_cli_topic"></a>

次のコード例は、`tag-resource` を使用する方法を示しています。

**AWS CLI**  
**既存のパイプにタグを付けるには**  
次の `tag-resource` の例では、`Demo_Pipe` という名前のパイプにタグを付けます。コマンドが成功した場合、出力は返りません。  

```
aws pipes tag-resource \
    --resource-arn arn:aws:pipes:us-east-1:123456789012:pipe/Demo_Pipe \
    --tags stack=Production
```
詳細については、*Amazon EventBridge ユーザーガイド*の「[Amazon EventBridge Pipes の概念](https://docs.aws.amazon.com/eventbridge/latest/userguide/pipes-concepts.html)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[TagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/pipes/tag-resource.html)」を参照してください。

### `untag-resource`
<a name="pipes_UntagResource_cli_topic"></a>

次のコード例は、`untag-resource` を使用する方法を示しています。

**AWS CLI**  
**既存のパイプからタグを削除するには**  
次の `untag-resource` の例では、`Demo_Pipe` という名前のパイプから、キーが `stack` のタグを削除します。コマンドが成功した場合、出力は返りません。  

```
aws pipes untag-resource \
    --resource-arn arn:aws:pipes:us-east-1:123456789012:pipe/Demo_Pipe \
    --tags stack
```
詳細については、*Amazon EventBridge ユーザーガイド*の「[Amazon EventBridge Pipes の概念](https://docs.aws.amazon.com/eventbridge/latest/userguide/pipes-concepts.html)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[UntagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/pipes/untag-resource.html)」を参照してください。

### `update-pipe`
<a name="pipes_UpdatePipe_cli_topic"></a>

次のコード例は、`update-pipe` を使用する方法を示しています。

**AWS CLI**  
**既存のパイプを更新するには**  
次の `update-pipe` の例では、CloudWatch Log 設定パラメータを追加して `Demo_Pipe` という名前のパイプを更新します。パイプの実行ロールが Log の送信先に対する適切なアクセス許可を持つように更新しています。  

```
aws pipes update-pipe \
    --name Demo_Pipe \
    --desired-state RUNNING \
    --log-configuration CloudwatchLogsLogDestination={LogGroupArn=arn:aws:logs:us-east-1:123456789012:log-group:/aws/vendedlogs/pipes/Demo_Pipe},Level=TRACE \
    --role-arn arn:aws:iam::123456789012:role/service-role/Amazon_EventBridge_Pipe_Demo_Pipe_28b3aa4f
```
出力:  

```
{
    "Arn": "arn:aws:pipes:us-east-1:123456789012:pipe/Demo_Pipe",
    "Name": "Demo_Pipe",
    "DesiredState": "RUNNING",
    "CurrentState": "UPDATING",
    "CreationTime": "2024-10-08T09:29:10-05:00",
    "LastModifiedTime": "2024-10-08T11:35:48-05:00"
}
```
詳細については、*Amazon EventBridge ユーザーガイド*の「[Amazon EventBridge Pipes の概念](https://docs.aws.amazon.com/eventbridge/latest/userguide/pipes-concepts.html)」を参照してください。  
+  API の詳細については、*AWS CLI コマンドリファレンス*の「[UpdatePipe](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/pipes/update-pipe.html)」を参照してください。