eladkal commented on code in PR #24099:
URL: https://github.com/apache/airflow/pull/24099#discussion_r891989118
##########
airflow/providers/amazon/aws/operators/rds.py:
##########
@@ -551,6 +551,94 @@ def execute(self, context: 'Context') -> str:
return json.dumps(delete_subscription, default=str)
+class RdsCreateDbInstanceOperator(RdsBaseOperator):
+ """
+ Creates an RDS DB instance
+
+ .. seealso::
+ For more information on how to use this operator, take a look at the
guide:
+ :ref:`howto/operator:RdsCreateDbInstanceOperator`
+
+ :param db_instance_identifier: The DB instance identifier, must start with
a letter and
+ contain from 1 to 63 letters, numbers, or hyphens
+ :param db_instance_class: The compute and memory capacity of the DB
instance, for example db.m5.large
+ :param engine: The name of the database engine to be used for this instance
+ :rds_kwargs: Named arguments to pass to boto3 RDS client function
``create_db_instance``
+ :param aws_conn_id: The Airflow connection used for AWS credentials.
+ """
+
+ def __init__(
+ self,
+ *,
+ db_instance_identifier: str,
+ db_instance_class: str,
+ engine: str,
+ rds_kwargs: Optional[Dict] = None,
+ aws_conn_id: str = "aws_default",
+ **kwargs,
+ ):
+ super().__init__(aws_conn_id=aws_conn_id, **kwargs)
+
+ self.db_instance_identifier = db_instance_identifier
+ self.db_instance_class = db_instance_class
+ self.engine = engine
+ self.rds_kwargs = rds_kwargs or {}
+
+ def execute(self, context: 'Context') -> str:
+ self.log.info(f"Creating new DB instance
{self.db_instance_identifier}")
+
+ create_db_instance = self.hook.conn.create_db_instance(
+ DBInstanceIdentifier=self.db_instance_identifier,
+ DBInstanceClass=self.db_instance_class,
+ Engine=self.engine,
+ **self.rds_kwargs,
+ )
+ self.hook.conn.get_waiter("db_instance_available").wait(
+ DBInstanceIdentifier=self.db_instance_identifier
+ )
+
+ return json.dumps(create_db_instance, default=str)
+
+
+class RdsDeleteDbInstanceOperator(RdsBaseOperator):
+ """
+ Deletes an RDS DB Instance
+
+ .. seealso::
+ For more information on how to use this operator, take a look at the
guide:
+ :ref:`howto/operator:RdsDeleteDbInstanceOperator`
+
+ :param db_instance_identifier: The DB instance identifier for the DB
instance to be deleted
+ :rds_kwargs: Named arguments to pass to boto3 RDS client function
``delete_db_instance``
Review Comment:
Can you add here link to the boto docs where user can find the option of the
possible kwargs?
##########
tests/providers/amazon/aws/operators/test_rds.py:
##########
@@ -450,3 +452,69 @@ def test_delete_event_subscription(self):
with pytest.raises(self.hook.conn.exceptions.ClientError):
self.hook.conn.describe_event_subscriptions(SubscriptionName=EXPORT_TASK_NAME)
+
+
[email protected](mock_rds is None, reason='mock_rds package not present')
+class TestRdsCreateDbInstanceOperator:
+ @classmethod
+ def setup_class(cls):
+ cls.dag = DAG('test_dag', default_args={'owner': 'airflow',
'start_date': DEFAULT_DATE})
+ cls.hook = RdsHook(aws_conn_id=AWS_CONN, region_name='us-east-1')
+
+ @classmethod
+ def teardown_class(cls):
+ del cls.dag
+ del cls.hook
+
+ @mock_rds
+ def test_create_db_instance(self):
+ create_db_instance_operator = RdsCreateDbInstanceOperator(
+ task_id='test_create_db_instance',
+ db_instance_identifier=DB_INSTANCE_NAME,
+ db_instance_class="db.m5.large",
+ engine="postgres",
+ rds_kwargs={
+ "DBName": DB_INSTANCE_NAME,
+ },
Review Comment:
If we have `db_instance_identifier` why do we need `DBName` in `rds_kwargs`?
##########
airflow/providers/amazon/aws/operators/rds.py:
##########
@@ -551,6 +551,94 @@ def execute(self, context: 'Context') -> str:
return json.dumps(delete_subscription, default=str)
+class RdsCreateDbInstanceOperator(RdsBaseOperator):
+ """
+ Creates an RDS DB instance
+
+ .. seealso::
+ For more information on how to use this operator, take a look at the
guide:
+ :ref:`howto/operator:RdsCreateDbInstanceOperator`
+
+ :param db_instance_identifier: The DB instance identifier, must start with
a letter and
+ contain from 1 to 63 letters, numbers, or hyphens
+ :param db_instance_class: The compute and memory capacity of the DB
instance, for example db.m5.large
+ :param engine: The name of the database engine to be used for this instance
+ :rds_kwargs: Named arguments to pass to boto3 RDS client function
``create_db_instance``
Review Comment:
Can you add here link to the boto docs where user can find the option of the
possible kwargs?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]