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.

tests/system/providers/amazon/aws/example_rds_snapshot.py[source]

create_snapshot = RdsCreateDbSnapshotOperator(
    task_id='create_snapshot',
    db_type='instance',
    db_identifier=rds_instance_name,
    db_snapshot_identifier=rds_snapshot_name,
)

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.

tests/system/providers/amazon/aws/example_rds_snapshot.py[source]

copy_snapshot = RdsCopyDbSnapshotOperator(
    task_id='copy_snapshot',
    db_type='instance',
    source_db_snapshot_identifier=rds_snapshot_name,
    target_db_snapshot_identifier=rds_snapshot_copy_name,
)

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.

tests/system/providers/amazon/aws/example_rds_snapshot.py[source]

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

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.

tests/system/providers/amazon/aws/example_rds_event.py[source]

create_subscription = RdsCreateEventSubscriptionOperator(
    task_id='create_subscription',
    subscription_name=rds_subscription_name,
    sns_topic_arn=sns_topic,
    source_type='db-instance',
    source_ids=[rds_instance_name],
    event_categories=['availability'],
)

Unsubscribe to an Amazon RDS event notification

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

tests/system/providers/amazon/aws/example_rds_event.py[source]

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

Create a database instance

To create a AWS DB instance you can use RdsCreateDbInstanceOperator.

tests/system/providers/amazon/aws/rds/example_rds_instance.py[source]

create_db_instance = RdsCreateDbInstanceOperator(
    task_id='create_db_instance',
    db_instance_identifier=RDS_DB_IDENTIFIER,
    db_instance_class="db.m5.large",
    engine="postgres",
    rds_kwargs={
        "MasterUsername": RDS_USERNAME,
        "MasterUserPassword": RDS_PASSWORD,
        "AllocatedStorage": 20,
    },
)

Delete a database instance

To delete a AWS DB instance you can use RDSDeleteDbInstanceOperator.

tests/system/providers/amazon/aws/rds/example_rds_instance.py[source]

delete_db_instance = RdsDeleteDbInstanceOperator(
    task_id='delete_db_instance',
    db_instance_identifier=RDS_DB_IDENTIFIER,
    rds_kwargs={
        "SkipFinalSnapshot": True,
    },
)

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.

tests/system/providers/amazon/aws/example_rds_snapshot.py[source]

snapshot_sensor = RdsSnapshotExistenceSensor(
    task_id='snapshot_sensor',
    db_type='instance',
    db_snapshot_identifier=rds_snapshot_name,
    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?