Airflow Summit 2025 is coming October 07-09. Register now for early bird ticket!

Amazon Redshift (Cluster)

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.

Prerequisite Tasks

To use these operators, you must do a few things:

Generic Parameters

aws_conn_id

Reference to Amazon Web Services Connection ID. If this parameter is set to None then the default boto3 behaviour is used without a connection lookup. Otherwise use the credentials stored in the Connection. Default: aws_default

region_name

AWS Region Name. If this parameter is set to None or omitted then region_name from AWS Connection Extra Parameter will be used. Otherwise use the specified value instead of the connection value. Default: None

verify

Whether or not to verify SSL certificates.

  • False - Do not validate SSL certificates.

  • path/to/cert/bundle.pem - A filename of the CA cert bundle to use. You can specify this argument if you want to use a different CA cert bundle than the one used by botocore.

If this parameter is set to None or is omitted then verify from AWS Connection Extra Parameter will be used. Otherwise use the specified value instead of the connection value. Default: None

botocore_config

The provided dictionary is used to construct a botocore.config.Config. This configuration can be used to configure Avoid Throttling exceptions, timeouts, etc.

Example, for more detail about parameters please have a look 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,
}

If this parameter is set to None or omitted then config_kwargs from AWS Connection Extra Parameter will be used. Otherwise use the specified value instead of the connection value. Default: None

Note

Specifying an empty dictionary, {}, will overwrite the connection configuration for botocore.config.Config

Operators

Create an Amazon Redshift cluster

To create an Amazon Redshift Cluster with the specified parameters you can use RedshiftCreateClusterOperator.

tests/system/amazon/aws/example_redshift.py[source]

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,
)

Resume an Amazon Redshift cluster

To resume a ‘paused’ Amazon Redshift cluster you can use RedshiftResumeClusterOperator You can also run this operator in deferrable mode by setting deferrable param to True. This will ensure that the task is deferred from the Airflow worker slot and polling for the task status happens on the trigger.

tests/system/amazon/aws/example_redshift.py[source]

resume_cluster = RedshiftResumeClusterOperator(
    task_id="resume_cluster",
    cluster_identifier=redshift_cluster_identifier,
)

Pause an Amazon Redshift cluster

To pause an available Amazon Redshift cluster you can use RedshiftPauseClusterOperator. You can also run this operator in deferrable mode by setting deferrable param to True

tests/system/amazon/aws/example_redshift.py[source]

pause_cluster = RedshiftPauseClusterOperator(
    task_id="pause_cluster",
    cluster_identifier=redshift_cluster_identifier,
)

Create an Amazon Redshift cluster snapshot

To create Amazon Redshift cluster snapshot you can use RedshiftCreateClusterSnapshotOperator

tests/system/amazon/aws/example_redshift.py[source]

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,
)

Delete an Amazon Redshift cluster snapshot

To delete Amazon Redshift cluster snapshot you can use RedshiftDeleteClusterSnapshotOperator

tests/system/amazon/aws/example_redshift.py[source]

delete_cluster_snapshot = RedshiftDeleteClusterSnapshotOperator(
    task_id="delete_cluster_snapshot",
    cluster_identifier=redshift_cluster_identifier,
    snapshot_identifier=redshift_cluster_snapshot_identifier,
)

Delete an Amazon Redshift cluster

To delete an Amazon Redshift cluster you can use RedshiftDeleteClusterOperator. You can also run this operator in deferrable mode by setting deferrable param to True

tests/system/amazon/aws/example_redshift.py[source]

delete_cluster = RedshiftDeleteClusterOperator(
    task_id="delete_cluster",
    cluster_identifier=redshift_cluster_identifier,
)

Sensors

Wait on an Amazon Redshift cluster state

To check the state of an Amazon Redshift Cluster until it reaches the target state or another terminal state you can use RedshiftClusterSensor.

tests/system/amazon/aws/example_redshift.py[source]

wait_cluster_available = RedshiftClusterSensor(
    task_id="wait_cluster_available",
    cluster_identifier=redshift_cluster_identifier,
    target_status="available",
    poke_interval=15,
    timeout=60 * 30,
)

Reference

Was this entry helpful?