

# 예: AWS CloudTrail을(를) 통해 Amazon EventBridge에서 S3 배치 작업 추적
<a name="batch-ops-examples-event-bridge-cloud-trail"></a>

Amazon S3 배치 작업 활동은 AWS CloudTrail에 이벤트로 기록됩니다. Amazon EventBridge에서 사용자 정의 규칙을 생성하고 이러한 이벤트를 원하는 대상 알림 리소스(예: Amazon Simple Notification Service(Amazon SNS))로 보낼 수 있습니다.

**참고**  
Amazon EventBridge는 이벤트를 관리하는 데 선호되는 방법입니다. Amazon CloudWatch Events와 EventBridge는 기본 서비스 및 API가 동일하지만 EventBridge가 더 많은 기능을 제공합니다. CloudWatch 또는 EventBridge에서 변경한 내용은 각 콘솔에 나타납니다. 자세한 내용은 *[Amazon EventBridge 사용 설명서](https://docs.aws.amazon.com/eventbridge/latest/userguide/)*를 참조하세요.

**Topics**
+ [CloudTrail에 기록된 S3 배치 작업 이벤트](#batch-ops-examples-cloud-trail-events)
+ [S3 배치 작업 이벤트 추적을 위한 EventBridge 규칙](#batch-ops-examples-event-bridge)

## CloudTrail에 기록된 S3 배치 작업 이벤트
<a name="batch-ops-examples-cloud-trail-events"></a>



배치 작업이 생성되면 CloudTrail에 `JobCreated` 이벤트로 기록됩니다. 작업이 실행되면 처리 중에 상태가 변경되고 다른 `JobStatusChanged` 이벤트가 CloudTrail에 기록됩니다. [CloudTrail 콘솔](https://console.aws.amazon.com/cloudtrail)에서 이러한 이벤트를 볼 수 있습니다. CloudTrail에 대한 자세한 내용은 [https://docs.aws.amazon.com/awscloudtrail/latest/userguide/how-cloudtrail-works.html](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/how-cloudtrail-works.html)를 참조하세요.

**참고**  
S3 배치 작업 `status-change` 이벤트만 CloudTrail에 기록됩니다.

**Example - CloudTrail에 의해 기록된 S3 배치 작업 완료 이벤트**  

```
{
    "eventVersion": "1.05",
    "userIdentity": {
        "accountId": "123456789012",
        "invokedBy": "s3.amazonaws.com"
    },
    "eventTime": "2020-02-05T18:25:30Z",
    "eventSource": "s3.amazonaws.com",
    "eventName": "JobStatusChanged",
    "awsRegion": "us-west-2",
    "sourceIPAddress": "s3.amazonaws.com",
    "userAgent": "s3.amazonaws.com",
    "requestParameters": null,
    "responseElements": null,
    "eventID": "f907577b-bf3d-4c53-b9ed-8a83a118a554",
    "readOnly": false,
    "eventType": "AwsServiceEvent",
    "recipientAccountId": "123412341234",
    "serviceEventDetails": {
        "jobId": "d6e58ec4-897a-4b6d-975f-10d7f0fb63ce",
        "jobArn": "arn:aws:s3:us-west-2:181572960644:job/d6e58ec4-897a-4b6d-975f-10d7f0fb63ce",
        "status": "Complete",
        "jobEventId": "b268784cf0a66749f1a05bce259804f5",
        "failureCodes": [],
        "statusChangeReason": []
    }
}
```

## S3 배치 작업 이벤트 추적을 위한 EventBridge 규칙
<a name="batch-ops-examples-event-bridge"></a>

다음 예제에서는 Amazon EventBridge에서 규칙을 생성하여 AWS CloudTrail에 의해 기록된 S3 배치 작업 이벤트를 선택한 대상으로 캡처하는 방법을 보여 줍니다.

이렇게 하려면 [이벤트에 반응하는 EventBridge 규칙 생성](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule.html)의 모든 단계에 따라 규칙을 생성합니다. 해당하는 경우 다음 S3 배치 작업 사용자 지정 이벤트 패턴 정책을 붙여넣고 원하는 대상 서비스를 선택합니다.

**S3 배치 작업 사용자 지정 이벤트 패턴 정책**

```
{
    "source": [
        "aws.s3"
    ],
    "detail-type": [
        "AWS Service Event via CloudTrail"
    ],
    "detail": {
        "eventSource": [
            "s3.amazonaws.com"
        ],
        "eventName": [
            "JobCreated",
            "JobStatusChanged"
        ]
    }
}
```

 다음 예제는 EventBridge 이벤트 규칙에서 Amazon Simple Queue Service(Amazon SQS)로 전송된 두 개의 배치 작업 이벤트입니다. 배치 작업은 처리 중에 여러 가지 상태(`New`, `Preparing`, `Active` 등)를 거치므로 각 작업에 대해 여러 메시지를 수신할 수 있습니다.

**Example - JobCreated 샘플 이벤트**  

```
{
    "version": "0",
    "id": "51dc8145-541c-5518-2349-56d7dffdf2d8",
    "detail-type": "AWS Service Event via CloudTrail",
    "source": "aws.s3",
    "account": "123456789012",
    "time": "2020-02-27T15:25:49Z",
    "region": "us-east-1",
    "resources": [],
    "detail": {
        "eventVersion": "1.05",
        "userIdentity": {
            "accountId": "11112223334444",
            "invokedBy": "s3.amazonaws.com"
        },
        "eventTime": "2020-02-27T15:25:49Z",
        "eventSource": "s3.amazonaws.com",
        "eventName": "JobCreated",
        "awsRegion": "us-east-1",
        "sourceIPAddress": "s3.amazonaws.com",
        "userAgent": "s3.amazonaws.com",
        "eventID": "7c38220f-f80b-4239-8b78-2ed867b7d3fa",
        "readOnly": false,
        "eventType": "AwsServiceEvent",
        "serviceEventDetails": {
            "jobId": "e849b567-5232-44be-9a0c-40988f14e80c",
            "jobArn": "arn:aws:s3:us-east-1:181572960644:job/e849b567-5232-44be-9a0c-40988f14e80c",
            "status": "New",
            "jobEventId": "f177ff24f1f097b69768e327038f30ac",
            "failureCodes": [],
            "statusChangeReason": []
        }
    }
}
```

**Example - JobStatusChanged 작업 완료 이벤트**  

```
{
  "version": "0",
  "id": "c8791abf-2af8-c754-0435-fd869ce25233",
  "detail-type": "AWS Service Event via CloudTrail",
  "source": "aws.s3",
  "account": "123456789012",
  "time": "2020-02-27T15:26:42Z",
  "region": "us-east-1",
  "resources": [],
  "detail": {
    "eventVersion": "1.05",
    "userIdentity": {
      "accountId": "1111222233334444",
      "invokedBy": "s3.amazonaws.com"
    },
    "eventTime": "2020-02-27T15:26:42Z",
    "eventSource": "s3.amazonaws.com",
    "eventName": "JobStatusChanged",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "s3.amazonaws.com",
    "userAgent": "s3.amazonaws.com",
    "eventID": "0238c1f7-c2b0-440b-8dbd-1ed5e5833afb",
    "readOnly": false,
    "eventType": "AwsServiceEvent",
    "serviceEventDetails": {
      "jobId": "e849b567-5232-44be-9a0c-40988f14e80c",
      "jobArn": "arn:aws:s3:us-east-1:181572960644:job/e849b567-5232-44be-9a0c-40988f14e80c",
      "status": "Complete",
      "jobEventId": "51f5ac17dba408301d56cd1b2c8d1e9e",
      "failureCodes": [],
      "statusChangeReason": []
    }
  }
}
```