Amazon Relational Database Service Documentation (RDS)

Amazon Relational Database Service (Amazon RDS) is a web service that makes it easier to set up, operate, and scale a relational database in the cloud. It provides cost-efficient, resizable capacity for an industry-standard relational database and manages common database administration tasks.

Prerequisite Tasks

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

Operators

Create a database snapshot

To create a snapshot of an Amazon RDS database instance or cluster you can use RDSCreateDBSnapshotOperator. The source database instance must be in the available or storage-optimization state.

airflow/providers/amazon/aws/example_dags/example_rds_snapshot.py[source]

create_snapshot = RdsCreateDbSnapshotOperator(
    task_id='create_snapshot',
    db_type='instance',
    db_identifier=RDS_DB_IDENTIFIER,
    db_snapshot_identifier=RDS_DB_SNAPSHOT_IDENTIFIER,
)

Copy a database snapshot

To copy a snapshot of an Amazon RDS database instance or cluster you can use RDSCopyDBSnapshotOperator. The source database snapshot must be in the available state.

airflow/providers/amazon/aws/example_dags/example_rds_snapshot.py[source]

copy_snapshot = RdsCopyDbSnapshotOperator(
    task_id='copy_snapshot',
    db_type='instance',
    source_db_snapshot_identifier=RDS_DB_IDENTIFIER,
    target_db_snapshot_identifier=f'{RDS_DB_IDENTIFIER}-copy',
)

Delete a database snapshot

To delete a snapshot of an Amazon RDS database instance or cluster you can use RDSDeleteDBSnapshotOperator. The database snapshot must be in the available state to be deleted.

airflow/providers/amazon/aws/example_dags/example_rds_snapshot.py[source]

delete_snapshot = RdsDeleteDbSnapshotOperator(
    task_id='delete_snapshot',
    db_type='instance',
    db_snapshot_identifier=RDS_DB_IDENTIFIER,
)

Export an Amazon RDS snapshot to Amazon S3

To export an Amazon RDS snapshot to Amazon S3 you can use RDSStartExportTaskOperator. The provided IAM role must have access to the S3 bucket.

airflow/providers/amazon/aws/example_dags/example_rds_export.py[source]

start_export = RdsStartExportTaskOperator(
    task_id='start_export',
    export_task_identifier=RDS_EXPORT_TASK_IDENTIFIER,
    source_arn=RDS_EXPORT_SOURCE_ARN,
    s3_bucket_name=BUCKET_NAME,
    s3_prefix=BUCKET_PREFIX,
    iam_role_arn=ROLE_ARN,
    kms_key_id=KMS_KEY_ID,
)

Cancel an Amazon RDS export task

To cancel an Amazon RDS export task to S3 you can use RDSCancelExportTaskOperator. Any data that has already been written to the S3 bucket isn't removed.

airflow/providers/amazon/aws/example_dags/example_rds_export.py[source]

cancel_export = RdsCancelExportTaskOperator(
    task_id='cancel_export',
    export_task_identifier=RDS_EXPORT_TASK_IDENTIFIER,
)

Subscribe to an Amazon RDS event notification

To create an Amazon RDS event subscription you can use RDSCreateEventSubscriptionOperator. This action requires an Amazon SNS topic Amazon Resource Name (ARN). Amazon RDS event notification is only available for not encrypted SNS topics. If you specify an encrypted SNS topic, event notifications are not sent for the topic.

airflow/providers/amazon/aws/example_dags/example_rds_event.py[source]

create_subscription = RdsCreateEventSubscriptionOperator(
    task_id='create_subscription',
    subscription_name=SUBSCRIPTION_NAME,
    sns_topic_arn=SNS_TOPIC_ARN,
    source_type='db-instance',
    source_ids=[RDS_DB_IDENTIFIER],
    event_categories=['availability'],
)

Unsubscribe to an Amazon RDS event notification

To delete an Amazon RDS event subscription you can use RDSDeleteEventSubscriptionOperator.

airflow/providers/amazon/aws/example_dags/example_rds_event.py[source]

delete_subscription = RdsDeleteEventSubscriptionOperator(
    task_id='delete_subscription',
    subscription_name=SUBSCRIPTION_NAME,
)

Sensors

Wait on an Amazon RDS snapshot status

To wait for an Amazon RDS snapshot with specific statuses you can use RdsSnapshotExistenceSensor. By default, the sensor waits for the existence of a snapshot with status available.

airflow/providers/amazon/aws/example_dags/example_rds_snapshot.py[source]

snapshot_sensor = RdsSnapshotExistenceSensor(
    task_id='snapshot_sensor',
    db_type='instance',
    db_snapshot_identifier=RDS_DB_IDENTIFIER,
    target_statuses=['available'],
)

Wait on an Amazon RDS export task status

To wait a for an Amazon RDS snapshot export task with specific statuses you can use RdsExportTaskExistenceSensor. By default, the sensor waits for the existence of a snapshot with status available.

airflow/providers/amazon/aws/example_dags/example_rds_export.py[source]

export_sensor = RdsExportTaskExistenceSensor(
    task_id='export_sensor',
    export_task_identifier=RDS_EXPORT_TASK_IDENTIFIER,
    target_statuses=['canceled'],
)

Was this entry helpful?