

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

# 를 사용하여 Step Functions 이벤트 전송 자동화 EventBridge
<a name="eventbridge-integration"></a>

EventBridge를 사용하면 Step Functions 표준 워크플로에서 이벤트를 선택하여 추가 처리를 위해 다른 서비스로 전송할 수 있습니다. 이 기법은 구성 요소를 느슨하게 연결하고 리소스를 모니터링하는 유연한 방법을 제공합니다.

Amazon EventBridge는 애플리케이션 구성 요소를 서로 연결하는 서버리스 서비스로, 확장 가능한 이벤트 기반 애플리케이션을 구축할 수 있습니다. 이벤트 기반 아키텍처는 *이벤트*를 내보내고 이에 응답하여 함께 작동하는 느슨하게 결합된 소프트웨어 시스템을 구축하는 스타일입니다. 이벤트는 상태 변경 또는 업데이트를 나타냅니다.

EventBridge를 사용하여 Step Functions 이벤트를 다른 서비스에 전달하면 [DescribeExecution](https://docs.aws.amazon.com/step-functions/latest/apireference/API_DescribeExecution.html) API를 지속적으로 호출하지 않고도 표준 워크플로를 모니터링하여 상태를 확인할 수 있습니다. 상태 머신 실행의 상태 변경 사항은 EventBridge로 자동으로 전송됩니다. 이러한 이벤트를 사용하여 서비스를 대상으로 지정할 수 있습니다. 예를 들어 이벤트는 AWS Lambda 함수를 호출하거나, Amazon Simple Notification Service(Amazon SNS) 주제에 메시지를 게시하거나, 다른 SFN 워크플로를 실행할 수 있습니다.

**이벤트 전송 작동 방식**  
Step Functions는 이벤트를 생성하고 모든 AWS 계정에 자동으로 프로비저닝되는 기본 EventBridge *이벤트 버스*로 전송합니다. 이벤트 버스는 이벤트를 수신하여 0개 이상의 목적지 또는 **대상에 전달하는 라우터입니다. 대상은 다른 AWS 서비스입니다. 이벤트를 규칙의 *이벤트 패턴*과 비교하는 이벤트 버스에 대한 규칙을 지정할 수 있습니다. 이벤트가 패턴과 일치하면 이벤트 버스는 이벤트를 지정된 대상에게 전송합니다. 다음 다이어그램은 이러한 프로세스를 보여줍니다.

![\[AWS 서비스는 규칙이 이벤트와 일치하는 이벤트를 EventBridge로 전송하고 대상으로 전송합니다.\]](http://docs.aws.amazon.com/ko_kr/step-functions/latest/dg/images/eventbridge-integration_shared_conceptual.png)


**표준 워크플로와 Express 워크플로 비교**  
표준 워크플로만 EventBridge에 이벤트를 내보냅니다. Express 워크플로 실행을 모니터링하려면 CloudWatch Logs를 사용하면 됩니다. [CloudWatch Logs에서 로깅](cw-logs.md)을(를) 참조하세요.

## Step Functions 이벤트
<a name="supported-events"></a>

Step Functions는 다음 이벤트를 기본 EventBridge 이벤트 버스로 자동으로 전송합니다. 규칙의 이벤트 패턴과 일치하는 이벤트는 [최대한](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-service-event.html#eb-service-event-delivery-level) 지정된 대상으로 전달됩니다. 이벤트는 비순차적으로 전달될 수 있습니다.

자세한 내용은 *Amazon EventBridge 사용 설명서*의 [EventBridge 이벤트](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-events.html)를 참조하세요.


| 이벤트 세부 정보 유형 | 설명 | 
| --- | --- | 
|  [실행 상태 변경](#event-detail-execution-status-change)  |  상태 머신 실행 상태의 변경을 나타냅니다. | 

## EventBridge를 사용하여 Step Functions 이벤트 전달
<a name="eventbridge-using-events-rules"></a>

EventBridge 기본 이벤트 버스가 Step Functions 이벤트를 대상으로 보내도록 하려면 규칙을 생성해야 합니다. 각 규칙에는 이벤트 버스에서 수신된 각 이벤트와 일치하는 EventBridge 패턴이 포함되어 있습니다. 이벤트 데이터가 지정된 이벤트 패턴과 일치하면 EventBridge는 해당 이벤트를 규칙의 대상으로 보냅니다.

이벤트 버스 규칙 생성에 대해 자세히 알아보려면 *EventBridge 사용 설명서*의 [이벤트에 대응하는 규칙 생성](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule.html)을 참조하세요.

 Step Functions 콘솔에서 특정 상태 시스템에 대한 이벤트 버스 규칙을 생성할 수도 있습니다.
+ 상태 머신의 **세부 정보** 페이지에서 **작업**을 선택한 다음 ***EventBridge* 규칙 생성**을 선택합니다.

  EventBridge 콘솔이 열리고 **규칙 생성** 페이지가 표시되면 상태 머신이 규칙의 이벤트 소스로 선택되어 있습니다.
+ *EventBridge 사용 설명서*의 [이벤트에 반응하는 규칙 생성](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule.html)에 설명된 절차를 따릅니다.

### Step Functions 이벤트와 일치하는 이벤트 패턴 생성
<a name="eventbridge-using-events-rules-patterns"></a>

각 이벤트 패턴은 다음을 포함하는 JSON 객체입니다.
+ 이벤트를 전송하는 서비스를 식별하는 `source` 속성입니다. Step Functions 이벤트의 경우 소스는 `aws.states`입니다.
+ (선택 사항): 일치시킬 이벤트 유형의 배열을 포함하는 `detail-type` 속성입니다.
+ (선택 사항): 일치시킬 다른 이벤트 데이터를 포함하는 `detail` 속성입니다.

예를 들어 다음 이벤트 패턴은 Step Functions의 모든 실행 상태 변경 이벤트와 일치합니다.

```
{
  "source": ["aws.states"],
  "detail-type": ["Step Functions Execution Status Change"]
}
```

다음 예제는 특정 상태 머신과 연결된 특정 실행과 일치하지만 해당 실행이 실패하거나 시간이 초과된 경우입니다.

```
{
  "source": ["aws.states"],
  "detail-type": ["Step Functions Execution Status Change"],
  "detail": {
    "status": ["FAILED", "TIMED_OUT"],
    "stateMachineArn": ["arn:aws:states:region:account-id:stateMachine:state-machine"],
    "executionArn": ["arn:aws:states:region:account-id:execution:state-machine-name:execution-name"]
  }
}
```

이벤트 작성에 대한 자세한 내용은 *EventBridge 사용 설명서*의 [이벤트 패턴](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-patterns.html)을 참조하세요.

## 이벤트를 사용하여 Step Functions 상태 머신 트리거
<a name="eventbridge-stepfunctions-as-target"></a>

또한 Step Functions 상태 머신을 EventBridge 이벤트 버스 규칙의 대상으로 지정할 수도 있습니다. 이렇게 하면 다른 AWS 서비스의 이벤트에 대한 응답으로 Step Functions 워크플로의 실행을 트리거할 수 있습니다.

자세한 정보는 *Amazon EventBridge 사용 설명서*의 [Amazon EventBridge 대상](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-targets.html)을 참조하세요.

## Step Functions 이벤트 세부 정보 참조
<a name="events-detail-reference"></a>

 AWS 서비스의 모든 이벤트에는 이벤트의 소스인 AWS 서비스, 이벤트가 생성된 시간, 이벤트가 발생한 계정 및 리전 등 이벤트에 대한 메타데이터가 포함된 공통 필드 세트가 있습니다. 이러한 일반 필드에 대한 정의는 *Amazon EventBridge 사용 설명서*의 [이벤트 구조 참조](https://docs.aws.amazon.com/eventbridge/latest/ref/overiew-event-structure.html)를 참조하세요.

또한 각 이벤트에는 해당 특정 이벤트와 관련된 데이터를 포함하는 `detail` 필드가 있습니다.

EventBridge를 사용하여 Step Functions 이벤트를 선택하고 관리할 때는 다음 사항을 염두에 두는 것이 유용합니다.
+ Step Functions의 모든 이벤트에 대한 `source` 필드는 `aws.states`로 설정됩니다.
+ `detail-type` 필드는 이벤트 유형을 지정합니다.

  예를 들어 `Step Functions Execution Status Change`입니다.
+ `detail` 필드는 해당 특정 이벤트와 관련된 데이터를 포함합니다.

Step Functions 이벤트와 일치하는 규칙을 활성화하는 이벤트 패턴을 구성하는 방법에 대한 자세한 내용은 *Amazon EventBridge 사용 설명서*의 [이벤트 패턴](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-patterns.html)을 참조하세요.

이벤트 및 EventBridge가 이벤트를 처리하는 방법에 대한 자세한 내용은 Amazon EventBridge 사용 설명서의 [Amazon EventBridge 이벤트](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-events.html)를 참조하세요.**

### 실행 상태 변경
<a name="event-detail-execution-status-change"></a>

상태 머신 실행 상태의 변경을 나타냅니다.

`source` 및 `detail-type` 필드는 Step Functions 이벤트에 대한 특정 값을 포함하므로 아래에 포함됩니다. 모든 이벤트에 포함된 다른 메타데이터 필드의 정의는 *Amazon EventBridge 사용 설명서*의 [이벤트 구조 참조](https://docs.aws.amazon.com/eventbridge/latest/ref/overiew-event-structure.html)를 참조하세요.

#### 이벤트 구조
<a name="event-detail-execution-status-change-structure"></a>

```
{
  . . .,
  "detail-type": "Step Functions Execution Status Change",
  "source"": "aws.states",
  . . .,
  "detail"": {
    "executionArn"" : "string",
    "input" : "string",
    "inputDetails" : {
      "included" : "boolean"
    },
    "name" : "string",
    "output" : "string",
    "outputDetails" : {
      "included" : "boolean"
    },
    "startDate" : "integer",
    "stateMachineArn" : "string",
    "stopDate" : "integer",
    "status" : "RUNNING | SUCCEEDED | FAILED | TIMED_OUT | ABORTED | PENDING_REDRIVE"
  }
}
```

#### 설명
<a name="event-detail-execution-status-change-remarks"></a>

실행 상태 변경 이벤트에서 해당 정의에 입력 속성을 포함할 수 있습니다. 일부 이벤트의 경우 실행 상태 변경 이벤트는 해당 정의에 출력 속성을 포함할 수도 있습니다.
+ EventBridge로 전송된 이스케이프 처리된 입력과 이스케이프 처리된 출력의 합산이 248KiB를 초과하면 입력은 제외됩니다. 마찬가지로 이스케이프 처리된 출력이 248KiB를 초과하면 출력이 제외됩니다. 이는 이벤트 할당량의 결과입니다.
+  `inputDetails` 및 `outputDetails` 속성을 사용하여 페이로드가 잘렸는지 여부를 확인할 수 있습니다. 자세한 내용은[`CloudWatchEventsExecutionDataDetails` 데이터 유형](https://docs.aws.amazon.com/step-functions/latest/apireference/API_CloudWatchEventsExecutionDataDetails.html)을 참조하세요.
+  표준 워크플로의 경우 [DescribeExecution](https://docs.aws.amazon.com/step-functions/latest/apireference/API_DescribeExecution.html)을 사용하여 전체 입력과 출력을 확인합니다.

   Express 워크플로에 `DescribeExecution`을 사용할 수 없습니다. 전체 입력/출력을 확인하려면 다음을 수행하면 됩니다.
  + 표준 워크플로로 Express 워크플로를 래핑합니다.
  + Amazon S3 ARN을 사용합니다. ARN 사용에 대한 자세한 내용은 [Step Functions에서 대용량 페이로드를 전달하는 대신 Amazon S3 ARN 사용](sfn-best-practices.md#avoid-exec-failures) 섹션을 참조하세요.

#### 예제
<a name="event-detail-execution-status-change-examples"></a>

**Example 실행 상태 변경: 실행 시작**  <a name="event-detail-execution-status-change-started.example"></a>

```
{
    "version": "0",
    "id": "315c1398-40ff-a850-213b-158f73e60175",
    "detail-type": "Step Functions Execution Status Change",
    "source": "aws.states",
    "account": "account-id",
    "time": "2019-02-26T19:42:21Z",
    "region": "us-east-2",
    "resources": [
      "arn:aws:states:us-east-2:account-id:execution:state-machine-name:execution-name"
    ],
    "detail": {
        "executionArn": "arn:aws:states:us-east-2:account-id:execution:state-machine-name:execution-name",
        "stateMachineArn": "arn:aws::states:us-east-2:account-id:stateMachine:state-machine",
        "name": "execution-name",
        "status": "RUNNING",
        "startDate": 1551225271984,
        "stopDate":  null,
        "input": "{}",
        "inputDetails": {
             "included": true
        },
        "output": null,
        "outputDetails": null
    }
}
```

**Example 실행 상태 변경: 실행 성공**  <a name="event-detail-execution-status-change-succeeded.example"></a>

```
{
    "version": "0",
    "id": "315c1398-40ff-a850-213b-158f73e60175",
    "detail-type": "Step Functions Execution Status Change",
    "source": "aws.states",
    "account": "account-id",
    "time": "2019-02-26T19:42:21Z",
    "region": "us-east-2",
    "resources": [
      "arn:aws:states:us-east-2:account-id:execution:state-machine-name:execution-name"
    ],
    "detail": {
        "executionArn": "arn:aws:states:us-east-2:account-id:execution:state-machine-name:execution-name",
        "stateMachineArn": "arn:aws:states:us-east-2:account-id:stateMachine:state-machine",
        "name": "execution-name",
        "status": "SUCCEEDED",
        "startDate": 1547148840101,
        "stopDate": 1547148840122,
        "input": "{}",
        "inputDetails": {
             "included": true
        },
        "output": "\"Hello World!\"",
        "outputDetails": {
             "included": true
        }
    }
}
```

**Example 실행 상태 변경: 실행 실패**  <a name="event-detail-execution-status-change-failed.example"></a>

```
{
    "version": "0",
    "id": "315c1398-40ff-a850-213b-158f73e60175",
    "detail-type": "Step Functions Execution Status Change",
    "source": "aws.states",
    "account": "account-id",
    "time": "2019-02-26T19:42:21Z",
    "region": "us-east-2",
    "resources": [
      "arn:aws:states:us-east-2:account-id:execution:state-machine-name:execution-name"
    ],
    "detail": {
        "executionArn": "arn:aws:states:us-east-2:account-id:execution:state-machine-name:execution-name",
        "stateMachineArn": "arn:aws:states:us-east-2:account-id:stateMachine:state-machine",
        "name": "execution-name",
        "status": "FAILED",
        "startDate": 1551225146847,
        "stopDate": 1551225151881,
        "input": "{}",
        "inputDetails": {
             "included": true
        },
        "output": null,
        "outputDetails": null
    }
}
```

**Example 실행 상태 변경: 시간 초과**  <a name="event-detail-execution-status-change-timed-out.example"></a>

```
{
    "version": "0",
    "id": "315c1398-40ff-a850-213b-158f73e60175",
    "detail-type": "Step Functions Execution Status Change",
    "source": "aws.states",
    "account": "account-id",
    "time": "2019-02-26T19:42:21Z",
    "region": "us-east-2",
    "resources": [
      "arn:aws:states:us-east-2:account-id:execution:state-machine-name:execution-name"
    ],
    "detail": {
        "executionArn": "arn:aws:states:us-east-2:account-id:execution:state-machine-name:execution-name",
        "stateMachineArn": "arn:aws:states:us-east-2:account-id:stateMachine:state-machine",
        "name": "execution-name",
        "status": "TIMED_OUT",
        "startDate": 1551224926156,
        "stopDate": 1551224927157,
        "input": "{}",
        "inputDetails": {
             "included": true
        },
        "output": null,
        "outputDetails": null
```

**Example 실행 상태 변경: 중단**  <a name="event-detail-execution-status-change-aborted.example"></a>

```
{
    "version": "0",
    "id": "315c1398-40ff-a850-213b-158f73e60175",
    "detail-type": "Step Functions Execution Status Change",
    "source": "aws.states",
    "account": "account-id",
    "time": "2019-02-26T19:42:21Z",
    "region": "us-east-2",
    "resources": [
      "arn:aws:states:us-east-2:account-id:execution:state-machine-name:execution-name"
    ],
    "detail": {
        "executionArn": "arn:aws:states:us-east-2:account-id:execution:state-machine-name:execution-name",
        "stateMachineArn": "arn:aws:states:us-east-2:account-id:stateMachine:state-machine",
        "name": "execution-name",
        "status": "ABORTED",
        "startDate": 1551225014968,
        "stopDate": 1551225017576,
        "input": "{}",
        "inputDetails": {
             "included": true
        },
        "output": null,
        "outputDetails": null
    }
}
```