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:

Generic Parameters

aws_conn_id

Reference to Amazon Web Services Connection ID. If this parameter is set to None then the default boto3 behaviour is used without a connection lookup. Otherwise use the credentials stored in the Connection. Default: aws_default

region_name

AWS Region Name. If this parameter is set to None or omitted then region_name from AWS Connection Extra Parameter will be used. Otherwise use the specified value instead of the connection value. Default: None

verify

Whether or not to verify SSL certificates.

  • False - Do not validate SSL certificates.

  • path/to/cert/bundle.pem - A filename of the CA cert bundle to use. You can specify this argument if you want to use a different CA cert bundle than the one used by botocore.

If this parameter is set to None or is omitted then verify from AWS Connection Extra Parameter will be used. Otherwise use the specified value instead of the connection value. Default: None

botocore_config

The provided dictionary is used to construct a botocore.config.Config. This configuration can be used to configure Avoid Throttling exceptions, timeouts, etc.

Example, for more detail about parameters please have a look botocore.config.Config
{
    "signature_version": "unsigned",
    "s3": {
        "us_east_1_regional_endpoint": True,
    },
    "retries": {
      "mode": "standard",
      "max_attempts": 10,
    },
    "connect_timeout": 300,
    "read_timeout": 300,
    "tcp_keepalive": True,
}

If this parameter is set to None or omitted then config_kwargs from AWS Connection Extra Parameter will be used. Otherwise use the specified value instead of the connection value. Default: None

Note

Specifying an empty dictionary, {}, will overwrite the connection configuration for botocore.config.Config

Operators

Create an AWS CloudFormation stack

To create a new AWS CloudFormation stack use CloudFormationCreateStackOperator.

tests/system/providers/amazon/aws/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.

tests/system/providers/amazon/aws/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

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

wait_for_stack_create = CloudFormationCreateStackSensor(
    task_id="wait_for_stack_create",
    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

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

wait_for_stack_delete = CloudFormationDeleteStackSensor(
    task_id="wait_for_stack_delete",
    stack_name=cloudformation_stack_name,
)

Was this entry helpful?