AWS CloudFormation

AWS CloudFormation enables you to create and provision AWS infrastructure deployments predictably and repeatedly. It helps you leverage AWS products such as Amazon EC2, Amazon Elastic Block Store, Amazon SNS, Elastic Load Balancing, and Auto Scaling to build highly reliable, highly scalable, cost-effective applications in the cloud without worrying about creating and configuring the underlying AWS infrastructure. AWS CloudFormation enables you to use a template file to create and delete a collection of resources together as a single unit (a stack).

Prerequisite Tasks

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

Operators

Create an AWS CloudFormation stack

To create a new AWS CloudFormation stack use CloudFormationCreateStackOperator.

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

create_stack = CloudFormationCreateStackOperator(
    task_id='create_stack',
    stack_name=CLOUDFORMATION_STACK_NAME,
    cloudformation_parameters=CLOUDFORMATION_CREATE_PARAMETERS,
)

Delete an AWS CloudFormation stack

To delete an AWS CloudFormation stack you can use CloudFormationDeleteStackOperator.

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

delete_stack = CloudFormationDeleteStackOperator(
    task_id='delete_stack', stack_name=CLOUDFORMATION_STACK_NAME
)

Sensors

Wait on an AWS CloudFormation stack creation state

To wait on the state of an AWS CloudFormation stack creation until it reaches a terminal state you can use CloudFormationCreateStackSensor

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

wait_for_stack_create = CloudFormationCreateStackSensor(
    task_id='wait_for_stack_creation', stack_name=CLOUDFORMATION_STACK_NAME
)

Wait on an AWS CloudFormation stack deletion state

To wait on the state of an AWS CloudFormation stack deletion until it reaches a terminal state you can use use CloudFormationDeleteStackSensor

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

wait_for_stack_delete = CloudFormationDeleteStackSensor(
    task_id='wait_for_stack_deletion', trigger_rule='all_done', stack_name=CLOUDFORMATION_STACK_NAME
)

Was this entry helpful?