Google Cloud AlloyDB Operators¶
The AlloyDB for PostgreSQL is a fully managed, PostgreSQL-compatible database service that’s designed for your most demanding workloads, including hybrid transactional and analytical processing. AlloyDB pairs a Google-built database engine with a cloud-based, multi-node architecture to deliver enterprise-grade performance, reliability, and availability.
Airflow provides operators to manage AlloyDB clusters.
Prerequisite Tasks¶
To use these operators, you must do a few things:
Select or create a Cloud Platform project using the Cloud Console.
Enable billing for your project, as described in the Google Cloud documentation.
Enable the API, as described in the Cloud Console documentation.
Install API libraries via pip.
pip install 'apache-airflow[google]'Detailed information is available for Installation.
Create cluster¶
To create an AlloyDB cluster (primary end secondary) you can use
AlloyDBCreateClusterOperator
.
create_cluster = AlloyDBCreateClusterOperator(
task_id="create_cluster",
cluster_id=CLUSTER_ID,
cluster_configuration=CLUSTER,
is_secondary=False,
location=GCP_LOCATION,
project_id=GCP_PROJECT_ID,
)
Update cluster¶
To update an AlloyDB cluster you can use
AlloyDBUpdateClusterOperator
.
update_cluster = AlloyDBUpdateClusterOperator(
task_id="update_cluster",
cluster_id=CLUSTER_ID,
cluster_configuration=CLUSTER_UPDATE,
update_mask=CLUSTER_UPDATE_MASK,
location=GCP_LOCATION,
project_id=GCP_PROJECT_ID,
)
Delete cluster¶
To delete an AlloyDB cluster you can use
AlloyDBDeleteClusterOperator
.
delete_cluster = AlloyDBDeleteClusterOperator(
task_id="delete_cluster",
project_id=GCP_PROJECT_ID,
location=GCP_LOCATION,
cluster_id=CLUSTER_ID,
)