Amazon Redshift Operators¶
Amazon Redshift manages all the work of setting up, operating, and scaling a data warehouse: provisioning capacity, monitoring and backing up the cluster, and applying patches and upgrades to the Amazon Redshift engine. You can focus on using your data to acquire new insights for your business and customers.
Airflow provides operators to manage your Redshift clusters.
Prerequisite Tasks¶
To use these operators, you must do a few things:
Create necessary resources using AWS Console or AWS CLI.
Install API libraries via pip.
pip install 'apache-airflow[amazon]'
Detailed information is available Installation
Manage Amazon Redshift Clusters¶
Amazon Redshift Cluster Operator¶
To create an Amazon Redshift Cluster with the specified parameters
RedshiftCreateClusterOperator
.
task_create_cluster = RedshiftCreateClusterOperator(
task_id="redshift_create_cluster",
cluster_identifier=REDSHIFT_CLUSTER_IDENTIFIER,
cluster_type="single-node",
node_type="dc2.large",
master_username="adminuser",
master_user_password="dummypass",
)
Amazon Redshift Cluster Sensor¶
To check the state of an Amazon Redshift Cluster until it reaches the target state or another terminal
state you can use RedshiftClusterSensor
.
task_wait_cluster_available = RedshiftClusterSensor(
task_id='sensor_redshift_cluster_available',
cluster_identifier=REDSHIFT_CLUSTER_IDENTIFIER,
target_status='available',
poke_interval=5,
timeout=60 * 15,
)
Resume an Amazon Redshift Cluster¶
To resume a 'paused' Amazon Redshift Cluster you can use
RedshiftResumeClusterOperator
task_resume_cluster = RedshiftResumeClusterOperator(
task_id='redshift_resume_cluster',
cluster_identifier=REDSHIFT_CLUSTER_IDENTIFIER,
)
Pause an Amazon Redshift Cluster¶
To pause an 'available' Amazon Redshift Cluster you can use
RedshiftPauseClusterOperator
task_pause_cluster = RedshiftPauseClusterOperator(
task_id='redshift_pause_cluster',
cluster_identifier=REDSHIFT_CLUSTER_IDENTIFIER,
)
Delete an Amazon Redshift Cluster¶
To delete an Amazon Redshift Cluster you can use
RedshiftDeleteClusterOperator
task_delete_cluster = RedshiftDeleteClusterOperator(
task_id="delete_cluster",
cluster_identifier=REDSHIFT_CLUSTER_IDENTIFIER,
)