

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

# 시작하기: Amazon EventBridge의 파이프 생성
<a name="pipes-get-started"></a>

파이프 및 기능에 익숙해지기 위해 CloudFormation 템플릿을 사용하여 EventBridge 파이프 및 관련 구성 요소를 설정합니다. 그런 다음 다양한 파이프 기능을 살펴볼 수 있습니다.

**작은 정보**  
보다 포괄적인 실습 학습 경험을 위해 [EventBridge 파이프 워크숍을](https://catalog.workshops.aws/eb-pipes) 사용해 보세요. 이 대화형 워크숍에서는 Lambda 보강을 통해 DynamoDB를 API Gateway에 연결하는 파이프를 구축하고 문제를 해결하는 방법을 안내합니다.

템플릿은 DynamoDB 테이블의 스트림을 Amazon SQS 대기열에 연결하는 EventBridge의 파이프를 생성합니다. 데이터베이스 테이블에서 레코드가 생성되거나 수정될 때마다 파이프는 결과 이벤트를 대기열로 보냅니다.

배포된 파이프는 다음으로 구성됩니다.
+ 이 경우 DynamoDB 테이블(및 스트림)은 파이프 소스 역할을 하고 Amazon SQS 대기열은 대상 역할을 합니다.
+ EventBridge에 DynamoDB 테이블 및 Amazon SQS 대기열에 액세스하는 데 필요한 권한을 부여하는 실행 역할입니다.
+ 테이블 항목이 생성(삽입)되거나 수정될 때 생성된 이벤트만 선택하는 이벤트 필터가 포함된 파이프 자체입니다.

템플릿의 특정 기술 세부 정보는 [템플릿 세부 정보](#pipes-get-started-template-details) 섹션을 참조하세요.

![\[데이터베이스 이벤트는 필터와 일치하고 일치하는 경우 대기열로 전송됩니다.\]](http://docs.aws.amazon.com/ko_kr/eventbridge/latest/userguide/images/pipes-get-started_eventbridge_architectural.svg)


## CloudFormation을 사용하여 파이프 생성
<a name="pipes-get-started-create"></a>

파이프 및 관련 리소스를 생성하기 위해 CloudFormation 템플릿을 생성하고 이를 사용하여 소스 및 대상으로 완성된 샘플 파이프가 포함된 스택을 생성합니다.

**중요**  
이 템플릿에서 스택을 생성할 경우 사용한 Amazon 리소스에 대한 요금이 청구됩니다.

### 템플릿 생성
<a name="pipes-get-started-file"></a>

우선 CloudFormation 템플릿을 만듭니다.

1. [템플릿](#pipes-get-started-template) 섹션에서 **JSON** 또는 **YAML** 탭의 복사 아이콘을 클릭하여 템플릿 콘텐츠를 복사합니다.

1. 템플릿 콘텐츠를 새 파일에 붙여 넣습니다.

1. 파일을 로컬에 저장합니다.

### 스택 생성
<a name="pipes-get-started-stack"></a>

다음으로, 저장한 템플릿을 사용하여 CloudFormation 스택을 프로비저닝합니다.

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

1. **스택** 페이지의 **스택 생성**에서 **새 리소스 사용(표준)**을 선택합니다.

1. 템플릿을 지정합니다.

   1. **사전 조건**에서 **기존 템플릿 선택**을 선택합니다.

   1. **템플릿 지정**에서 **템플릿 파일 업로드**를 선택합니다.

   1. **파일 선택**을 선택하고 템플릿 파일로 이동한 후 해당 파일을 선택합니다.

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

1. 스택 세부 정보를 지정합니다.

   1. 스택 이름을 입력합니다.

   1. 파라미터의 경우 기본값을 적용하거나 직접 입력합니다.

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

1. 스택 옵션을 구성합니다.

   1. **스택 실패 옵션**에서 **새로 생성된 모든 리소스 삭제**를 선택합니다.
**참고**  
이 옵션을 선택하면 스택 생성에 실패하더라도 삭제 정책에서 보존하도록 지정한 리소스에 대해서는 요금이 청구되지 않습니다. 자세한 내용은 *CloudFormation CLI 사용 설명서*의 [`DeletionPolicy` 속성](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-deletionpolicy.html) 섹션을 참조하세요.

   1. 모든 기타 기본값을 적용합니다.

   1. **기능**에서 CloudFormation이 계정에 IAM 리소스를 생성할 수 있음을 승인하는 확인란을 선택합니다.

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

1. 스택 세부 정보를 검토하고 **제출**을 선택합니다.

**CloudFormation을 사용하여 스택 생성(AWS CLI)**

를 사용하여 스택 AWS CLI 을 생성할 수도 있습니다.
+ [https://docs.aws.amazon.com/cli/latest/reference/cloudformation/create-stack.html](https://docs.aws.amazon.com/cli/latest/reference/cloudformation/create-stack.html) 명령을 사용합니다.
  + 스택 이름을 지정하여 기본 템플릿 파라미터 값을 수락합니다. `template-body` 파라미터를 사용하여 템플릿 콘텐츠를 전송하거나 `template-url`을 사용하여 URL 위치를 지정합니다.

    ```
    aws cloudformation create-stack \
      --stack-name eventbridge-rule-tutorial \
      --template-body template-contents \
      --capabilities CAPABILITY_IAM
    ```
  + 하나 이상의 템플릿 파라미터의 기본값을 재정의합니다. 예제:

    ```
    aws cloudformation create-stack \
      --stack-name eventbridge-rule-tutorial \
      --template-body template-contents \
      --parameters \
        ParameterKey=SourceTableName,ParameterValue=pipe-example-source \
        ParameterKey=TargetQueueName,ParameterValue=pipe-example-target \
        ParameterKey=PipeName,ParameterValue=pipe-with-filtering-example \
      --capabilities CAPABILITY_IAM
    ```

CloudFormation에서 스택을 생성합니다. 스택 생성이 완료되면 스택 리소스를 사용할 준비가 된 것입니다. 스택 세부 정보 페이지의 **리소스** 탭을 사용하여 계정에 프로비저닝된 리소스를 볼 수 있습니다.

## 파이프 기능 탐색
<a name="pipes-get-started-using"></a>

파이프가 생성되면 EventBridge 콘솔을 사용하여 파이프 작업을 관찰하고 이벤트 전송을 테스트할 수 있습니다.

1. [https://console.aws.amazon.com/events/home?\$1/pipes](https://console.aws.amazon.com/events/home?#/pipes)에서 EventBridge 콘솔을 엽니다.

1. 생성한 파이프를 선택합니다.

   파이프 세부 정보 페이지의 **파이프 구성 요소** 섹션에는 파이프를 구성하는 리소스가 표시되고 각 구성 요소에 대한 자세한 정보를 제공하는 탭이 포함되어 있습니다.  
![\[파이프 세부 정보 페이지에는 파이프의 소스, 필터 및 대상 구성 요소가 그래픽으로 표시됩니다.\]](http://docs.aws.amazon.com/ko_kr/eventbridge/latest/userguide/images/pipes-get-started_eventbridge_pipe-detail.png)

   파이프에 대해 생성한 실행 역할은 **설정** 탭의 **권한** 섹션에서 찾을 수 있습니다.

### 파이프 필터 검사
<a name="pipes-get-started-using-filter"></a>

파이프 작업을 테스트하기 전에 대상으로 전송되는 이벤트를 제어하기 위해 지정한 필터를 살펴보겠습니다. 파이프는 필터 기준과 일치하는 이벤트만 대상으로 전송하고 다른 모든 이벤트는 삭제됩니다. 이 경우 테이블 항목이 생성되거나 수정될 때만 이벤트가 Amazon SQS 대기열로 전송되기를 원합니다.
+ 파이프 세부 정보 페이지의 **파이프 구성 요소**에서 **필터링** 탭을 선택합니다.

  `eventName`이 `INSERT` 또는 `MODIFY`로 설정된 이벤트만 선택하는 필터를 포함했습니다.

  ```
  {
    "eventName": ["INSERT", "MODIFY"]
  }
  ```

### 파이프를 통해 이벤트 전송
<a name="pipes-get-started-using-source"></a>

다음으로 파이프 소스에서 이벤트를 생성하여 파이프 필터링 및 전송이 올바르게 작동하는지 테스트합니다. 이를 위해 파이프 소스로 지정한 DynamoDB 테이블에서 항목을 생성하고 편집합니다.

1. 파이프 세부 정보 페이지의 **파이프 구성 요소**에서 **소스** 탭을 선택합니다.

1. **소스**에서 DynamoDB 스트림 이름을 선택합니다.

   그러면 소스 테이블 세부 정보가 표시된 별도의 창에서 DynamoDB 콘솔이 열립니다.

1. **항목 탐색**을 선택합니다.

1. 테이블에 항목을 생성하여 `INSERT` 이벤트를 생성합니다.

   1. **항목 생성**을 선택합니다.

   1. **앨범** 및 **아티스트** 속성 값을 추가합니다.

   1. **항목 생성**을 선택합니다.

1. 항목을 편집하여 `DELETE` 및 `INSERT` 이벤트를 생성합니다.

   1. 목록에서 항목을 선택하고 **작업** 메뉴에서 **항목 편집**을 선택합니다.

   1. **앨범** 또는 **아티스트** 속성에 새 값을 입력합니다.

   1. 항목 키의 값을 변경하고 있음을 확인하는 상자를 선택한 다음 **항목 재생성**을 선택합니다.

      그러면 항목이 삭제된 다음 다시 생성되어 `DELETE` 이벤트가 생성된 다음 새 `INSERT` 이벤트가 생성됩니다.

1. 항목에 속성을 추가하여 `MODIFY` 이벤트를 생성합니다.

   1. 목록에서 항목을 선택하고 **작업** 메뉴에서 **항목 편집**을 선택합니다.

   1. **새 속성 추가** 메뉴에서 **숫자**를 선택합니다.

   1. 속성 이름에 **연도**를 입력한 다음 속성 값을 입력합니다. [**Save and close**]를 선택합니다.

### 파이프를 통한 이벤트 전송 확인
<a name="pipes-get-started-using-target"></a>

마지막으로 파이프가 DynamoDB에서 테이블 항목을 생성하고 편집하여 생성한 이벤트를 성공적으로 필터링하고 전송했는지 확인합니다.

1. 파이프 세부 정보 페이지의 **파이프 구성 요소**에서 **대상** 탭을 선택합니다.

1. **대상**에서 Amazon SQS 대기열 이름을 선택합니다.

   그러면 대상 대기열 세부 정보가 표시된 별도의 창에서 Amazon SQS 콘솔이 열립니다.

1. [**메시지 전송 및 수신(Send and receive messages)**]을 선택합니다.

1. **메시지 수신**에서 **메시지 폴링**을 선택합니다.

   Amazon SQS는 수신된 메시지를 대기열에 로드합니다. 개별 메시지를 클릭하여 세부 정보를 확인합니다.

   대기열에는 3가지 이벤트 메시지가 있어야 합니다.
   + 유형 `INSERT` 2개, 하나는 테이블 항목을 처음 생성할 때 생성되고 다른 하나는 키 값을 변경하여 항목을 다시 생성할 때 생성됩니다.
   + 유형 `MODIFY` 중 하나, 테이블 항목에 속성을 추가할 때 생성됩니다.

   키 값을 변경하여 테이블 항목을 삭제하고 다시 생성할 때 생성되었더라도 대기열에 유형 `DELETE`의 이벤트 메시지가 없습니다. 지정한 파이프 필터는 `INSERT` 및 `MODIFY`에서만 선택하므로 파이프는 `DELETE` 이벤트를 대기열로 전송하지 않고 필터링했습니다.

## 정리: 리소스 삭제
<a name="pipes-get-started-delete"></a>

마지막 단계로, 스택을 삭제하고 해당 스택에 포함된 리소스를 삭제합니다.

**중요**  
스택에 포함된 Amazon 리소스가 존재하는 한 해당 리소스에 대한 요금이 청구됩니다.

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

1. **스택** 페이지에서 템플릿을 통해 생성한 스택을 선택하고 **삭제**를 선택한 다음, **삭제**를 확인합니다.

   CloudFormation은 스택 및 해당 스택에 포함된 모든 리소스의 삭제를 시작합니다.

## CloudFormation 템플릿 세부 정보
<a name="pipes-get-started-template-details"></a>

이 템플릿은 리소스를 생성하고 계정에 권한을 부여합니다.

### 리소스
<a name="pipes-get-started-template-resources"></a>

이 자습서에서 CloudFormation 템플릿은 계정에 다음과 같은 리소스를 생성합니다.

**중요**  
이 템플릿에서 스택을 생성할 경우 사용한 Amazon 리소스에 대한 요금이 청구됩니다.
+ [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html): 파이프의 이벤트 소스 역할을 하는 DynamoDB 테이블입니다.
+ [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-sqs-queue.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-sqs-queue.html): 파이프를 통해 흐르는 이벤트의 대상 역할을 하는 Amazon SQS 대기열입니다.
+ [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html): 계정의 EventBridge Pipes 서비스에 권한을 부여하는 IAM 실행 역할입니다.
+ [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-pipes-pipe.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-pipes-pipe.html): DynamoDB 테이블을 Amazon SQS 대기열에 연결하는 파이프입니다.

### 권한
<a name="pipes-get-started-template-perms"></a>

템플릿에는 실행 역할을 나타내는 `AWS::IAM::Role` 리소스가 포함되어 있습니다. 이 역할은 EventBridge Pipes 서비스(`pipes.amazonaws.com`)에 계정에 다음 권한을 부여합니다.

다음 권한은 DynamoDB 테이블로 범위가 지정되고 템플릿이 파이프의 이벤트 소스로 생성하는 스트림입니다.
+ `dynamodb:DescribeStream`
+ `dynamodb:GetRecords`
+ `dynamodb:GetShardIterator`
+ `dynamodb:ListStreams`

다음 권한은 스택이 파이프의 대상으로 생성하는 Amazon SQS 대기열로 범위가 지정됩니다.
+ `sqs:SendMessage`

## CloudFormation 템플릿
<a name="pipes-get-started-template"></a>

아래의 JSON 또는 YAML 코드를 별도의 파일로 저장하여 이 자습서의 CloudFormation 템플릿으로 사용하세요.

------
#### [ JSON ]

```
{
  "AWSTemplateFormatVersion": "2010-09-09",

 "Description" : "[AWSDocs] EventBridge: pipes-get-started",

  "Parameters" : {
    "SourceTableName" : {
      "Type" : "String",
      "Default" : "pipe-example-source",
      "Description" : "Specify the name of the table to provision as the pipe source, or accept the default."
    },
  "TargetQueueName" : {
    "Type" : "String",
    "Default" : "pipe-example-target",
    "Description" : "Specify the name of the queue to provision as the pipe target, or accept the default."
  },
    "PipeName" : {
      "Type" : "String",
      "Default" : "pipe-with-filtering-example",
      "Description" : "Specify the name of the table to provision as the pipe source, or accept the default."
    }
},
  "Resources": {
    "PipeSourceDynamoDBTable": {
      "Type": "AWS::DynamoDB::Table",
      "Properties": {
        "AttributeDefinitions": [{
            "AttributeName": "Album",
            "AttributeType": "S"
          },
          {
            "AttributeName": "Artist",
            "AttributeType": "S"
          }

        ],
        "KeySchema": [{
            "AttributeName": "Album",
            "KeyType": "HASH"

          },
          {
            "AttributeName": "Artist",
            "KeyType": "RANGE"
          }
        ],
        "ProvisionedThroughput": {
          "ReadCapacityUnits": 10,
          "WriteCapacityUnits": 10
        },
        "StreamSpecification": {
          "StreamViewType": "NEW_AND_OLD_IMAGES"
        },
        "TableName": { "Ref" : "SourceTableName" }
      }
    },
    "PipeTargetQueue": {
      "Type": "AWS::SQS::Queue",
      "Properties": {
        "QueueName": { "Ref" : "TargetQueueName" }
      }
    },
    "PipeTutorialPipeRole": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "AssumeRolePolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [{
            "Effect": "Allow",
            "Principal": {
              "Service": "pipes.amazonaws.com"
            },
            "Action": "sts:AssumeRole",
            "Condition": {
              "StringLike": {
                "aws:SourceArn": {
                  "Fn::Join": [
                    "",
                    [
                      "arn:",
                      { "Ref": "AWS::Partition" },
                      ":pipes:",
                      { "Ref": "AWS::Region" },
                      ":",
                      { "Ref": "AWS::AccountId" },
                      ":pipe/",
                      { "Ref": "PipeName" }
                    ]
                  ]
                },
                "aws:SourceAccount": { "Ref" : "AWS::AccountId" }
              }
            }
          }]
        },
        "Description" : "EventBridge Pipe template example. Execution role that grants the pipe the permissions necessary to send events to the specified pipe.",
        "Path": "/",
        "Policies": [{
            "PolicyName": "SourcePermissions",
            "PolicyDocument": {
              "Version": "2012-10-17",
              "Statement": [{
                "Effect": "Allow",
                "Action": [
                  "dynamodb:DescribeStream",
                  "dynamodb:GetRecords",
                  "dynamodb:GetShardIterator",
                  "dynamodb:ListStreams"
                ],
                "Resource": [
                  { "Fn::GetAtt" : [ "PipeSourceDynamoDBTable", "StreamArn" ] }
                ]
              }]
            }
          },
          {
            "PolicyName": "TargetPermissions",
            "PolicyDocument": {
              "Version": "2012-10-17",
              "Statement": [{
                "Effect": "Allow",
                "Action": [
                  "sqs:SendMessage"
                ],
                "Resource": [
                  { "Fn::GetAtt" : [ "PipeTargetQueue", "Arn" ] }
                ]
              }]
            }
          }
        ]
      }
  },
    "PipeWithFiltering": {
      "Type": "AWS::Pipes::Pipe",
      "Properties": {
        "Description" : "EventBridge Pipe template example. Pipe that receives events from a DynamoDB stream, applies a filter, and sends matching events on to an SQS Queue.",
        "Name": { "Ref" : "PipeName" },
        "RoleArn": {"Fn::GetAtt" : ["PipeTutorialPipeRole", "Arn"] },
        "Source": { "Fn::GetAtt" : [ "PipeSourceDynamoDBTable", "StreamArn" ] },
        "SourceParameters": {
          "DynamoDBStreamParameters" : {
            "StartingPosition" : "LATEST"
         },
        "FilterCriteria" : {
          "Filters" : [ {
            "Pattern" : "{ \"eventName\": [\"INSERT\", \"MODIFY\"] }"
         }]
        }
        },
        "Target": { "Fn::GetAtt" : [ "PipeTargetQueue", "Arn" ] }
      }
    }
  }
}
```

------
#### [ YAML ]

```
AWSTemplateFormatVersion: '2010-09-09'
Description: '[AWSDocs] EventBridge: pipes-get-started'
Parameters:
  SourceTableName:
    Type: String
    Default: pipe-example-source
    Description: Specify the name of the table to provision as the pipe source, or accept the default.
  TargetQueueName:
    Type: String
    Default: pipe-example-target
    Description: Specify the name of the queue to provision as the pipe target, or accept the default.
  PipeName:
    Type: String
    Default: pipe-with-filtering-example
    Description: Specify the name of the table to provision as the pipe source, or accept the default.
Resources:
  PipeSourceDynamoDBTable:
    Type: AWS::DynamoDB::Table
    Properties:
      AttributeDefinitions:
        - AttributeName: Album
          AttributeType: S
        - AttributeName: Artist
          AttributeType: S
      KeySchema:
        - AttributeName: Album
          KeyType: HASH
        - AttributeName: Artist
          KeyType: RANGE
      ProvisionedThroughput:
        ReadCapacityUnits: 10
        WriteCapacityUnits: 10
      StreamSpecification:
        StreamViewType: NEW_AND_OLD_IMAGES
      TableName: !Ref SourceTableName
  PipeTargetQueue:
    Type: AWS::SQS::Queue
    Properties:
      QueueName: !Ref TargetQueueName
  PipeTutorialPipeRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal:
              Service: pipes.amazonaws.com
            Action: sts:AssumeRole
            Condition:
              StringLike:
                aws:SourceArn: !Join
                  - ''
                  - - 'arn:'
                    - !Ref AWS::Partition
                    - ':pipes:'
                    - !Ref AWS::Region
                    - ':'
                    - !Ref AWS::AccountId
                    - ':pipe/'
                    - !Ref PipeName
                aws:SourceAccount: !Ref AWS::AccountId
      Description: EventBridge Pipe template example. Execution role that grants the pipe the permissions necessary to send events to the specified pipe.
      Path: /
      Policies:
        - PolicyName: SourcePermissions
          PolicyDocument:
            Version: '2012-10-17'
            Statement:
              - Effect: Allow
                Action:
                  - dynamodb:DescribeStream
                  - dynamodb:GetRecords
                  - dynamodb:GetShardIterator
                  - dynamodb:ListStreams
                Resource:
                  - !GetAtt PipeSourceDynamoDBTable.StreamArn
        - PolicyName: TargetPermissions
          PolicyDocument:
            Version: '2012-10-17'
            Statement:
              - Effect: Allow
                Action:
                  - sqs:SendMessage
                Resource:
                  - !GetAtt PipeTargetQueue.Arn
  PipeWithFiltering:
    Type: AWS::Pipes::Pipe
    Properties:
      Description: EventBridge Pipe template example. Pipe that receives events from a DynamoDB stream, applies a filter, and sends matching events on to an SQS Queue.
      Name: !Ref PipeName
      RoleArn: !GetAtt PipeTutorialPipeRole.Arn
      Source: !GetAtt PipeSourceDynamoDBTable.StreamArn
      SourceParameters:
        DynamoDBStreamParameters:
          StartingPosition: LATEST
        FilterCriteria:
          Filters:
            - Pattern: '{ "eventName": ["INSERT", "MODIFY"] }'
      Target: !GetAtt PipeTargetQueue.Arn
```

------