1515# KIND, either express or implied. See the License for the
1616# specific language governing permissions and limitations
1717# under the License.
18- """This module contains CloudFormation create/delete stack operators."""
18+ """This module contains AWS CloudFormation create/delete stack operators."""
1919from __future__ import annotations
2020
2121from typing import TYPE_CHECKING , Sequence
2222
23- from airflow .models import BaseOperator
2423from airflow .providers .amazon .aws .hooks .cloud_formation import CloudFormationHook
24+ from airflow .providers .amazon .aws .operators .base_aws import AwsBaseOperator
25+ from airflow .providers .amazon .aws .utils .mixins import aws_template_fields
2526
2627if TYPE_CHECKING :
2728 from airflow .utils .context import Context
2829
2930
30- class CloudFormationCreateStackOperator (BaseOperator ):
31+ class CloudFormationCreateStackOperator (AwsBaseOperator [ CloudFormationHook ] ):
3132 """
32- An operator that creates a CloudFormation stack.
33+ An operator that creates a AWS CloudFormation stack.
3334
3435 .. seealso::
3536 For more information on how to use this operator, take a look at the guide:
3637 :ref:`howto/operator:CloudFormationCreateStackOperator`
3738
3839 :param stack_name: stack name (templated)
39- :param cloudformation_parameters: parameters to be passed to CloudFormation.
40- :param aws_conn_id: aws connection to uses
40+ :param cloudformation_parameters: parameters to be passed to AWS CloudFormation.
41+ :param aws_conn_id: The Airflow connection used for AWS credentials.
42+ If this is ``None`` or empty then the default boto3 behaviour is used. If
43+ running Airflow in a distributed manner and aws_conn_id is None or
44+ empty, then default boto3 configuration would be used (and must be
45+ maintained on each worker node).
46+ :param region_name: AWS region_name. If not specified then the default boto3 behaviour is used.
47+ :param verify: Whether or not to verify SSL certificates. See:
48+ https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html
49+ :param botocore_config: Configuration dictionary (key-values) for botocore client. See:
50+ https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html
4151 """
4252
43- template_fields : Sequence [ str ] = ( "stack_name" , "cloudformation_parameters" )
44- template_ext : Sequence [str ] = ( )
53+ aws_hook_class = CloudFormationHook
54+ template_fields : Sequence [str ] = aws_template_fields ( "stack_name" , "cloudformation_parameters" )
4555 ui_color = "#6b9659"
4656
47- def __init__ (
48- self , * , stack_name : str , cloudformation_parameters : dict , aws_conn_id : str = "aws_default" , ** kwargs
49- ):
57+ def __init__ (self , * , stack_name : str , cloudformation_parameters : dict , ** kwargs ):
5058 super ().__init__ (** kwargs )
5159 self .stack_name = stack_name
5260 self .cloudformation_parameters = cloudformation_parameters
53- self .aws_conn_id = aws_conn_id
5461
5562 def execute (self , context : Context ):
5663 self .log .info ("CloudFormation parameters: %s" , self .cloudformation_parameters )
57-
58- cloudformation_hook = CloudFormationHook (aws_conn_id = self .aws_conn_id )
59- cloudformation_hook .create_stack (self .stack_name , self .cloudformation_parameters )
64+ self .hook .create_stack (self .stack_name , self .cloudformation_parameters )
6065
6166
62- class CloudFormationDeleteStackOperator (BaseOperator ):
67+ class CloudFormationDeleteStackOperator (AwsBaseOperator [ CloudFormationHook ] ):
6368 """
64- An operator that deletes a CloudFormation stack.
65-
66- :param stack_name: stack name (templated)
67- :param cloudformation_parameters: parameters to be passed to CloudFormation.
69+ An operator that deletes a AWS CloudFormation stack.
6870
6971 .. seealso::
7072 For more information on how to use this operator, take a look at the guide:
7173 :ref:`howto/operator:CloudFormationDeleteStackOperator`
7274
73- :param aws_conn_id: aws connection to uses
75+ :param stack_name: stack name (templated)
76+ :param cloudformation_parameters: parameters to be passed to CloudFormation.
77+ :param aws_conn_id: The Airflow connection used for AWS credentials.
78+ If this is ``None`` or empty then the default boto3 behaviour is used. If
79+ running Airflow in a distributed manner and aws_conn_id is None or
80+ empty, then default boto3 configuration would be used (and must be
81+ maintained on each worker node).
82+ :param region_name: AWS region_name. If not specified then the default boto3 behaviour is used.
83+ :param verify: Whether or not to verify SSL certificates. See:
84+ https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html
85+ :param botocore_config: Configuration dictionary (key-values) for botocore client. See:
86+ https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html
7487 """
7588
76- template_fields : Sequence [ str ] = ( "stack_name" ,)
77- template_ext : Sequence [str ] = ( )
89+ aws_hook_class = CloudFormationHook
90+ template_fields : Sequence [str ] = aws_template_fields ( "stack_name" )
7891 ui_color = "#1d472b"
7992 ui_fgcolor = "#FFF"
8093
@@ -93,6 +106,4 @@ def __init__(
93106
94107 def execute (self , context : Context ):
95108 self .log .info ("CloudFormation Parameters: %s" , self .cloudformation_parameters )
96-
97- cloudformation_hook = CloudFormationHook (aws_conn_id = self .aws_conn_id )
98- cloudformation_hook .delete_stack (self .stack_name , self .cloudformation_parameters )
109+ self .hook .delete_stack (self .stack_name , self .cloudformation_parameters )
0 commit comments