

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# Feature Processor パイプラインのスケジュール済みの実行とイベントベースの実行
<a name="feature-store-feature-processor-schedule-pipeline"></a>

Amazon SageMaker Feature Store Feature Processing パイプラインの実行は、事前設定されたスケジュールに基づいて、または別の AWS サービスイベントの結果として、自動的かつ非同期的に開始するように設定できます。例えば、Feature Processing パイプラインを毎月 1 日に実行するようにスケジュールを指定したり、2 つのパイプラインを連結して、ソースパイプラインの実行が完了した後にターゲットパイプラインが自動的に実行されるように指定したりできます。

**Topics**
+ [スケジュールベースの実行](#feature-store-feature-processor-schedule-pipeline-schedule-based)
+ [イベントベースの実行](#feature-store-feature-processor-schedule-pipeline-event-based)

## スケジュールベースの実行
<a name="feature-store-feature-processor-schedule-pipeline-schedule-based"></a>

Feature Processor SDK は、Amazon EventBridge スケジューラとの統合により、Feature Processor パイプラインを定期的に実行するための [https://sagemaker.readthedocs.io/en/stable/api/prep_data/feature_store.html#sagemaker.feature_store.feature_processor.schedule](https://sagemaker.readthedocs.io/en/stable/api/prep_data/feature_store.html#sagemaker.feature_store.feature_processor.schedule) API を提供します。スケジュールは、Amazon EventBridge でサポートされているのと同じ式で [https://docs.aws.amazon.com/scheduler/latest/APIReference/API_CreateSchedule.html#scheduler-CreateSchedule-request-ScheduleExpression](https://docs.aws.amazon.com/scheduler/latest/APIReference/API_CreateSchedule.html#scheduler-CreateSchedule-request-ScheduleExpression) パラメータを使用して、`at` 式、`rate` 式、`cron` 式を使って指定できます。schedule API は、スケジュールが既に指定されている場合は更新し、指定されていない場合は作成するという点で、意義的には upsert オペレーションです。EventBridge 式と例の詳細については、「EventBridge スケジューラユーザーガイド」の「[Schedule types on EventBridge Scheduler](https://docs.aws.amazon.com/scheduler/latest/UserGuide/schedule-types.html)」を参照してください。

次の例では、`at` 式、`rate` 式、`cron` 式を使用して、Feature Processor [https://sagemaker.readthedocs.io/en/stable/api/prep_data/feature_store.html#sagemaker.feature_store.feature_processor.schedule](https://sagemaker.readthedocs.io/en/stable/api/prep_data/feature_store.html#sagemaker.feature_store.feature_processor.schedule) API を使用しています。

```
from sagemaker.feature_store.feature_processor import schedule
pipeline_name='feature-processor-pipeline'

event_bridge_schedule_arn = schedule(
    pipeline_name=pipeline_name, 
    schedule_expression="at(2020-11-30T00:00:00)"
)

event_bridge_schedule_arn = schedule(
    pipeline_name=pipeline_name, 
    schedule_expression="rate(24 hours)"
)

event_bridge_schedule_arn = schedule(
    pipeline_name=pipeline_name, 
    schedule_expression="cron(0 0-23/1 ? * * 2023-2024)"
)
```

`schedule` API の日付と時刻の入力のデフォルトタイムゾーンは UTC です。EventBridge Scheduler のスケジュール式の詳細については、「EventBridge Scheduler API Reference」ドキュメントの「[https://docs.aws.amazon.com/scheduler/latest/APIReference/API_CreateSchedule.html#scheduler-CreateSchedule-request-ScheduleExpression](https://docs.aws.amazon.com/scheduler/latest/APIReference/API_CreateSchedule.html#scheduler-CreateSchedule-request-ScheduleExpression)」を参照してください。

スケジュール済み Feature Processor パイプラインを実行すると、変換関数にスケジュール済みの実行時間が与えられ、これをべき等性トークンまたは日付範囲ベースの入力の固定基準点として使用できます。スケジュールを無効 (一時停止) にしたり再び有効にしたりするには、[https://sagemaker.readthedocs.io/en/stable/api/prep_data/feature_store.html#sagemaker.feature_store.feature_processor.schedule](https://sagemaker.readthedocs.io/en/stable/api/prep_data/feature_store.html#sagemaker.feature_store.feature_processor.schedule) API の `state` パラメータをそれぞれ `‘DISABLED’` または `‘ENABLED’` にして使用します。

Feature Processor の詳細については、「[Feature Processor SDK データソース](feature-store-feature-processor-data-sources-sdk.md)」を参照してください。

## イベントベースの実行
<a name="feature-store-feature-processor-schedule-pipeline-event-based"></a>

Feature Processing パイプラインは、 AWS イベントが発生すると自動的に実行されるように設定できます。Feature Processing SDK は、ソースイベントのリストとターゲットパイプラインのリストを受け入れる [https://sagemaker.readthedocs.io/en/stable/api/prep_data/feature_store.html#sagemaker.feature_store.feature_processor.put_trigger](https://sagemaker.readthedocs.io/en/stable/api/prep_data/feature_store.html#sagemaker.feature_store.feature_processor.put_trigger) 関数を提供しています。ソースイベントは、パイプラインと[実行ステータス](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribePipelineExecution.html#sagemaker-DescribePipelineExecution-response-PipelineExecutionStatus)イベントを指定する [https://sagemaker.readthedocs.io/en/stable/api/prep_data/feature_store.html#sagemaker.feature_store.feature_processor.FeatureProcessorPipelineEvent](https://sagemaker.readthedocs.io/en/stable/api/prep_data/feature_store.html#sagemaker.feature_store.feature_processor.FeatureProcessorPipelineEvent) のインスタンスである必要があります。

`put_trigger` 関数は、イベントをルーティングするように Amazon EventBridge ルールとターゲットを設定し、 AWS イベントに応答する EventBridge イベントパターンを指定できます。これらの概念の詳細については、「Amazon EventBridge [ルール](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-rules.html)」、[「ターゲット](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-targets.html)」、[「イベントパターン](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-patterns.html)」を参照してください。

トリガーは有効にしたり無効にしたりできます。EventBridge は、`put_trigger` API の `role_arn` パラメータで指定されたロールを使用して、ターゲットパイプラインの実行を開始します。SDK が Amazon SageMaker Studio Classic または Notebook 環境で使用されている場合、デフォルトで実行ロールが使用されます。実行ロールを取得する方法の詳細については、「[実行ロールを取得する](sagemaker-roles.md#sagemaker-roles-get-execution-role)」を参照してください。

次の例では、以下を設定します。
+ `to_pipeline` API を使用する SageMaker AI パイプライン。ターゲットパイプライン名 (`target-pipeline`) と変換関数 (`transform`) を受け取ります。Feature Processor と transform 関数の詳細については、「[Feature Processor SDK データソース](feature-store-feature-processor-data-sources-sdk.md)」を参照してください。
+ `put_trigger` API を使用するトリガー。イベントの `FeatureProcessorPipelineEvent` とターゲットパイプライン名 (`target-pipeline`) を受け取ります。

  `FeatureProcessorPipelineEvent` は、ソースパイプライン (`source-pipeline`) のステータスが `Succeeded` になった場合のトリガーを定義します。Feature Processor Pipeline イベント関数の詳細については、特徴量ストアの「ドキュメントを読む」の「[https://sagemaker.readthedocs.io/en/stable/api/prep_data/feature_store.html#sagemaker.feature_store.feature_processor.FeatureProcessorPipelineEvent](https://sagemaker.readthedocs.io/en/stable/api/prep_data/feature_store.html#sagemaker.feature_store.feature_processor.FeatureProcessorPipelineEvent)」を参照してください。

```
from sagemaker.feature_store.feature_processor import put_trigger, to_pipeline, FeatureProcessorPipelineEvent

to_pipeline(pipeline_name="target-pipeline", step=transform)

put_trigger(
    source_pipeline_events=[
        FeatureProcessorPipelineEvent(
            pipeline_name="source-pipeline",
            status=["Succeeded"]
        )
    ],
    target_pipeline="target-pipeline"
)
```

イベントベースのトリガーを使用して、Feature Processor パイプラインの継続的な実行と自動再試行を作成する例については、「[イベントベースのトリガーを使用した継続的な実行と自動再試行](feature-store-feature-processor-examples.md#feature-store-feature-processor-examples-continuous-execution-automatic-retries)」を参照してください。

イベントベースのトリガーを使用して、継続的な*ストリーミング*とイベントベースのトリガーで自動再試行を作成する例については、「[ストリーミングのカスタムデータソースの例](feature-store-feature-processor-data-sources-custom-examples.md#feature-store-feature-processor-data-sources-custom-examples-streaming)」を参照してください。