AWS Step Functions¶
AWS Step Functions 使通过可视化工作流的方式轻松协调分布式应用程序的各个组件,将其作为一系列步骤。您可以快速构建和运行状态机,以可靠且可扩展的方式执行应用程序的步骤。
前提任务¶
要使用这些操作器,您需要做几件事:
通过 pip 安装 API 库。
pip install 'apache-airflow[amazon]'详细信息请参见 Airflow® 安装
设置连接.
通用参数¶
- aws_conn_id
引用 Amazon Web Services 连接 ID。如果此参数设置为
None
,则使用默认的 boto3 行为,不查找连接。否则,使用连接中存储的凭据。默认值:aws_default
- region_name
AWS 区域名称。如果此参数设置为
None
或省略,则使用 AWS 连接附加参数 中的 region_name。否则,使用指定的值而不是连接中的值。默认值:None
- verify
是否验证 SSL 证书。
False
- 不验证 SSL 证书。path/to/cert/bundle.pem
- 要使用的 CA 证书捆绑包文件名。如果您想使用与 botocore 不同的 CA 证书捆绑包,可以指定此参数。
如果此参数设置为
None
或省略,则使用 AWS 连接附加参数 中的 verify。否则,使用指定的值而不是连接中的值。默认值:None
- botocore_config
提供的字典用于构建 botocore.config.Config。此配置可用于配置 避免限制异常、超时等。
示例,有关参数的更多详细信息,请参考 botocore.config.Config¶{ "signature_version": "unsigned", "s3": { "us_east_1_regional_endpoint": True, }, "retries": { "mode": "standard", "max_attempts": 10, }, "connect_timeout": 300, "read_timeout": 300, "tcp_keepalive": True, }
如果此参数设置为
None
或省略,则使用 AWS 连接附加参数 中的 config_kwargs。否则,使用指定的值而不是连接中的值。默认值:None
注意
指定一个空字典
{}
将覆盖 botocore.config.Config 的连接配置。
操作器¶
启动 AWS Step Functions 状态机执行¶
要启动新的 AWS Step Functions 状态机执行,您可以使用 StepFunctionStartExecutionOperator
。您还可以通过将 deferrable
参数设置为 True
,以可延迟模式运行此操作器。
tests/system/amazon/aws/example_step_functions.py
start_execution = StepFunctionStartExecutionOperator(
task_id="start_execution", state_machine_arn=state_machine_arn
)
获取 AWS Step Functions 执行输出¶
要从 AWS Step Function 状态机执行中获取输出,您可以使用 StepFunctionGetExecutionOutputOperator
。
tests/system/amazon/aws/example_step_functions.py
get_execution_output = StepFunctionGetExecutionOutputOperator(
task_id="get_execution_output", execution_arn=execution_arn
)
传感器¶
等待 AWS Step Functions 状态机执行状态¶
要等待 AWS Step Function 状态机执行的状态直到其达到终端状态,您可以使用 StepFunctionExecutionSensor
。
tests/system/amazon/aws/example_step_functions.py
wait_for_execution = StepFunctionExecutionSensor(
task_id="wait_for_execution", execution_arn=execution_arn
)