시작하기: Amazon EventBridge 파이프 생성 - Amazon EventBridge

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

시작하기: Amazon EventBridge 파이프 생성

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

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

배포된 파이프는 다음으로 구성됩니다.

  • 파이프 소스 역할을 하는 DynamoDB 테이블(및 스트림)과 대상 역할을 하는 Amazon SQS 대기열입니다.

  • EventBridge에 DynamoDB 테이블 및 Amazon SQS 대기열에 액세스하는 데 필요한 권한을 부여하는 실행 역할입니다.

  • 테이블 항목이 생성(삽입)되거나 수정될 때 생성된 이벤트만 선택하는 이벤트 필터가 포함된 파이프 자체입니다.

템플릿의 특정 기술 세부 정보는 섹션을 참조하세요템플릿 세부 정보.

데이터베이스 이벤트는 필터와 일치하고 일치하는 경우 대기열로 전송됩니다.

를 사용하여 파이프 생성 AWS CloudFormation

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

중요

이 템플릿에서 스택을 생성할 때 사용되는 Amazon 리소스에 대한 요금이 청구됩니다.

템플릿 생성

먼저 CloudFormation 템플릿을 생성합니다.

  1. 템플릿 섹션에서 JSON 또는 YAML 탭의 복사 아이콘을 클릭하여 템플릿 콘텐츠를 복사합니다.

  2. 템플릿 내용을 새 파일에 붙여 넣습니다.

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

스택 생성

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

  1. AWS CloudFormation 콘솔을 엽니다.

  2. 스택 페이지의 스택 생성 메뉴에서 새 리소스(표준)를 선택합니다.

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

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

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

    3. 파일 선택을 선택하고 템플릿 파일로 이동한 다음 선택합니다.

    4. 다음을 선택합니다.

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

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

    2. 파라미터의 경우 기본값을 수락하거나 직접 입력합니다.

    3. 다음을 선택합니다.

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

    1. 스택 실패 옵션에서 새로 생성된 모든 리소스 삭제를 선택합니다.

      참고

      이 옵션을 선택하면 스택 생성에 실패하더라도 삭제 정책에서 보존하도록 지정하는 리소스에 대한 요금이 청구되지 않습니다. 자세한 내용은 AWS CloudFormation 사용 설명서DeletionPolicy 속성을 참조하세요.

    2. 다른 모든 기본값을 수락합니다.

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

    4. 다음을 선택합니다.

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

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

파이프 기능 탐색

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

  1. https://console.aws.amazon.com/events/home?#/pipes EventBridge 콘솔을 엽니다.

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

    파이프 세부 정보 페이지의 파이프 구성 요소 섹션에는 파이프를 구성하는 리소스가 표시되고 각 구성 요소에 대한 자세한 정보를 제공하는 탭이 포함되어 있습니다.

    파이프 세부 정보 페이지에는 파이프의 소스, 필터 및 대상 구성 요소가 그래픽으로 표시됩니다.

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

파이프 필터 검사

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

  • 파이프 세부 정보 페이지의 파이프 구성 요소에서 필터링 탭을 선택합니다.

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

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

파이프를 통해 이벤트 전송

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

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

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

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

  3. 테이블 항목 탐색을 선택합니다.

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

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

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

    3. 항목 생성을 선택합니다.

  5. 항목을 편집하여 DELETEINSERT 이벤트를 생성합니다.

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

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

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

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

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

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

    2. 새 속성 추가 메뉴에서 번호를 선택합니다.

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

파이프를 통한 이벤트 전송 확인

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

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

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

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

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

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

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

    대기열에는 세 가지 이벤트 메시지가 있어야 합니다.

    • 유형 2개INSERT, 하나는 테이블 항목을 처음 생성할 때 생성되고 다른 하나는 키 값을 변경하여 항목을 다시 생성할 때 생성됩니다.

    • 테이블 항목에 속성을 추가할 때 MODIFY생성되는 유형 중 하나입니다.

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

정리: 리소스 삭제

마지막 단계로 스택과 스택에 포함된 리소스를 삭제합니다.

중요

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

  1. AWS CloudFormation 콘솔을 엽니다.

  2. 스택 페이지에서 템플릿에서 생성된 스택을 선택하고 삭제를 선택한 다음 삭제를 확인합니다.

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

CloudFormation 템플릿 세부 정보

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

리소스

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

중요

이 템플릿에서 스택을 생성할 때 사용되는 Amazon 리소스에 대한 요금이 청구됩니다.

  • AWS::DynamoDB::Table: 파이프의 이벤트 소스 역할을 하는 DynamoDB 테이블입니다.

  • AWS::SQS::Queue: 파이프를 통해 흐르는 이벤트의 대상 역할을 하는 Amazon SQS 대기열입니다.

  • AWS::IAM::Role: 계정의 EventBridge Pipes 서비스에 권한을 부여하는 IAM 실행 역할입니다.

  • AWS::Pipes::Pipe: DynamoDB 테이블을 Amazon SQS 대기열에 연결하는 파이프입니다.

권한

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

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

  • dynamodb:DescribeStream

  • dynamodb:GetRecords

  • dynamodb:GetShardIterator

  • dynamodb:ListStreams

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

  • sqs:SendMessage

CloudFormation 템플릿

다음 JSON 또는 YAML 코드를이 자습서의 CloudFormation 템플릿으로 사용할 별도의 파일로 저장합니다.

JSON
{ "AWSTemplateFormatVersion": "2010-09-09", "Description" : "EventBridge Pipe template example. Provisions a pipe, along with a DynamoDB stream as the pipe source and an SQS queue as the pipe target. Also provisions an execution role that contains the necessary permissions to access both the source and target. Once provisioned, the pipe receives events from the DynamoDB data stream, applies a filter, and sends matching events on to an SQS Queue. You will be billed for the Amazon resources used if you create a stack from this template.", "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: EventBridge Pipe template example. Provisions a pipe, along with a DynamoDB stream as the pipe source and an SQS queue as the pipe target. Also provisions an execution role that contains the necessary permissions to access both the source and target. Once provisioned, the pipe receives events from the DynamoDB data stream, applies a filter, and sends matching events on to an SQS Queue. You will be billed for the Amazon resources used if you create a stack from this template. 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