Amazon Redshift (叢集)¶
Amazon Redshift 管理設定、操作和擴展資料倉儲的所有工作:配置容量、監控和備份叢集,以及將修補程式和升級應用於 Amazon Redshift 引擎。您可以專注於使用您的資料來為您的業務和客戶獲取新的見解。
先決條件任務¶
要使用這些運算子,您必須執行以下幾項操作
使用 AWS Console 或 AWS CLI 建立必要的資源。
透過 pip 安裝 API 函式庫。
pip install 'apache-airflow[amazon]'詳細資訊請參閱 Airflow® 安裝
設定連線.
運算子¶
建立 Amazon Redshift 叢集¶
要使用指定的參數建立 Amazon Redshift 叢集,您可以使用 RedshiftCreateClusterOperator
。
tests/system/amazon/aws/example_redshift.py
create_cluster = RedshiftCreateClusterOperator(
task_id="create_cluster",
cluster_identifier=redshift_cluster_identifier,
vpc_security_group_ids=[security_group_id],
cluster_subnet_group_name=cluster_subnet_group_name,
publicly_accessible=False,
cluster_type="single-node",
node_type="dc2.large",
master_username=DB_LOGIN,
master_user_password=DB_PASS,
)
恢復 Amazon Redshift 叢集¶
要恢復「已暫停」的 Amazon Redshift 叢集,您可以使用 RedshiftResumeClusterOperator
。您也可以透過將 deferrable
參數設定為 True
,以可延遲模式執行此運算子。這將確保任務從 Airflow worker 插槽延遲,並且任務狀態的輪詢發生在觸發器上。
tests/system/amazon/aws/example_redshift.py
resume_cluster = RedshiftResumeClusterOperator(
task_id="resume_cluster",
cluster_identifier=redshift_cluster_identifier,
)
暫停 Amazon Redshift 叢集¶
要暫停 available
的 Amazon Redshift 叢集,您可以使用 RedshiftPauseClusterOperator
。您也可以透過將 deferrable
參數設定為 True
,以可延遲模式執行此運算子。
tests/system/amazon/aws/example_redshift.py
pause_cluster = RedshiftPauseClusterOperator(
task_id="pause_cluster",
cluster_identifier=redshift_cluster_identifier,
)
建立 Amazon Redshift 叢集快照¶
要建立 Amazon Redshift 叢集快照,您可以使用 RedshiftCreateClusterSnapshotOperator
tests/system/amazon/aws/example_redshift.py
create_cluster_snapshot = RedshiftCreateClusterSnapshotOperator(
task_id="create_cluster_snapshot",
cluster_identifier=redshift_cluster_identifier,
snapshot_identifier=redshift_cluster_snapshot_identifier,
poll_interval=30,
max_attempt=100,
retention_period=1,
wait_for_completion=True,
)
刪除 Amazon Redshift 叢集快照¶
要刪除 Amazon Redshift 叢集快照,您可以使用 RedshiftDeleteClusterSnapshotOperator
tests/system/amazon/aws/example_redshift.py
delete_cluster_snapshot = RedshiftDeleteClusterSnapshotOperator(
task_id="delete_cluster_snapshot",
cluster_identifier=redshift_cluster_identifier,
snapshot_identifier=redshift_cluster_snapshot_identifier,
)
刪除 Amazon Redshift 叢集¶
要刪除 Amazon Redshift 叢集,您可以使用 RedshiftDeleteClusterOperator
。您也可以透過將 deferrable
參數設定為 True
,以可延遲模式執行此運算子。
tests/system/amazon/aws/example_redshift.py
delete_cluster = RedshiftDeleteClusterOperator(
task_id="delete_cluster",
cluster_identifier=redshift_cluster_identifier,
)
感測器¶
等待 Amazon Redshift 叢集狀態¶
要檢查 Amazon Redshift 叢集的狀態,直到它達到目標狀態或另一個終端狀態,您可以使用 RedshiftClusterSensor
。
tests/system/amazon/aws/example_redshift.py
wait_cluster_available = RedshiftClusterSensor(
task_id="wait_cluster_available",
cluster_identifier=redshift_cluster_identifier,
target_status="available",
poke_interval=15,
timeout=60 * 30,
)