stacker.providers.aws package

Submodules

stacker.providers.aws.default module

class stacker.providers.aws.default.Provider(session, region=None, interactive=False, replacements_only=False, recreate_failed=False, service_role=None, **kwargs)[source]

Bases: stacker.providers.base.BaseProvider

AWS CloudFormation Provider

COMPLETE_STATUSES = ('CREATE_COMPLETE', 'DELETE_COMPLETE', 'UPDATE_COMPLETE', 'UPDATE_ROLLBACK_COMPLETE')
DELETED_STATUS = 'DELETE_COMPLETE'
FAILED_STATUSES = ('CREATE_FAILED', 'ROLLBACK_FAILED', 'ROLLBACK_COMPLETE', 'DELETE_FAILED', 'UPDATE_ROLLBACK_FAILED', 'UPDATE_ROLLBACK_COMPLETE')
IN_PROGRESS_STATUSES = ('CREATE_IN_PROGRESS', 'UPDATE_IN_PROGRESS', 'DELETE_IN_PROGRESS', 'UPDATE_COMPLETE_CLEANUP_IN_PROGRESS')
RECREATION_STATUSES = ('CREATE_FAILED', 'ROLLBACK_FAILED', 'ROLLBACK_COMPLETE')
ROLLING_BACK_STATUSES = ('ROLLBACK_IN_PROGRESS', 'UPDATE_ROLLBACK_IN_PROGRESS')
create_stack(fqn, template, parameters, tags, force_change_set=False, stack_policy=None, **kwargs)[source]

Create a new Cloudformation stack.

Parameters:
  • fqn (str) – The fully qualified name of the Cloudformation stack.
  • template (stacker.providers.base.Template) – A Template object to use when creating the stack.
  • parameters (list) – A list of dictionaries that defines the parameter list to be applied to the Cloudformation stack.
  • tags (list) – A list of dictionaries that defines the tags that should be applied to the Cloudformation stack.
  • force_change_set (bool) – Whether or not to force change set use.
  • stack_policy (stacker.providers.base.Template) – A template object representing a stack policy.
deal_with_changeset_stack_policy(fqn, stack_policy)[source]

Set a stack policy when using changesets.

ChangeSets don’t allow you to set stack policies in the same call to update them. This sets it before executing the changeset if the stack policy is passed in.

Parameters:stack_policy (stacker.providers.base.Template) – A template object representing a stack policy.
default_update_stack(fqn, template, old_parameters, parameters, tags, stack_policy=None, **kwargs)[source]

Update a Cloudformation stack in default mode.

Parameters:
  • fqn (str) – The fully qualified name of the Cloudformation stack.
  • template (stacker.providers.base.Template) – A Template object to use when updating the stack.
  • old_parameters (list) – A list of dictionaries that defines the parameter list on the existing Cloudformation stack.
  • parameters (list) – A list of dictionaries that defines the parameter list to be applied to the Cloudformation stack.
  • tags (list) – A list of dictionaries that defines the tags that should be applied to the Cloudformation stack.
  • stack_policy (stacker.providers.base.Template) – A template object representing a stack policy.
destroy_stack(stack, **kwargs)[source]
get_events(stack_name, chronological=True)[source]

Get the events in batches and return in chronological order

get_output_dict(stack)[source]
get_outputs(stack_name, *args, **kwargs)[source]
get_rollback_status_reason(stack_name)[source]

Process events and returns latest roll back reason

get_stack(stack_name, **kwargs)[source]
get_stack_info(stack)[source]

Get the template and parameters of the stack currently in AWS

Returns [ template, parameters ]

get_stack_name(stack, **kwargs)[source]
get_stack_status(stack, **kwargs)[source]
get_stack_tags(stack, **kwargs)[source]
interactive_update_stack(fqn, template, old_parameters, parameters, stack_policy, tags, **kwargs)[source]

Update a Cloudformation stack in interactive mode.

Parameters:
  • fqn (str) – The fully qualified name of the Cloudformation stack.
  • template (stacker.providers.base.Template) – A Template object to use when updating the stack.
  • old_parameters (list) – A list of dictionaries that defines the parameter list on the existing Cloudformation stack.
  • parameters (list) – A list of dictionaries that defines the parameter list to be applied to the Cloudformation stack.
  • stack_policy (stacker.providers.base.Template) – A template object representing a stack policy.
  • tags (list) – A list of dictionaries that defines the tags that should be applied to the Cloudformation stack.
is_stack_completed(stack, **kwargs)[source]
is_stack_destroyed(stack, **kwargs)[source]
is_stack_failed(stack, **kwargs)[source]
is_stack_in_progress(stack, **kwargs)[source]
is_stack_recreatable(stack, **kwargs)[source]
is_stack_rolling_back(stack, **kwargs)[source]
noninteractive_changeset_update(fqn, template, old_parameters, parameters, stack_policy, tags, **kwargs)[source]

Update a Cloudformation stack using a change set.

This is required for stacks with a defined Transform (i.e. SAM), as the default update_stack API cannot be used with them.

Parameters:
  • fqn (str) – The fully qualified name of the Cloudformation stack.
  • template (stacker.providers.base.Template) – A Template object to use when updating the stack.
  • old_parameters (list) – A list of dictionaries that defines the parameter list on the existing Cloudformation stack.
  • parameters (list) – A list of dictionaries that defines the parameter list to be applied to the Cloudformation stack.
  • stack_policy (stacker.providers.base.Template) – A template object representing a stack policy.
  • tags (list) – A list of dictionaries that defines the tags that should be applied to the Cloudformation stack.
static params_as_dict(parameters_list)[source]
prepare_stack_for_update(stack, tags)[source]

Prepare a stack for updating

It may involve deleting the stack if is has failed it’s initial creation. The deletion is only allowed if:

  • The stack contains all the tags configured in the current context;
  • The stack is in one of the statuses considered safe to re-create
  • recreate_failed is enabled, due to either being explicitly enabled by the user, or because interactive mode is on.
Parameters:
  • stack (dict) – a stack object returned from get_stack
  • tags (list) – list of expected tags that must be present in the stack if it must be re-created
Returns:

True if the stack can be updated, False if it must be

re-created

Return type:

bool

select_update_method(force_interactive, force_change_set)[source]

Select the correct update method when updating a stack.

Parameters:
  • force_interactive (str) – Whether or not to force interactive mode no matter what mode the provider is in.
  • force_change_set (bool) – Whether or not to force change set use.
Returns:

The correct object method to use when updating.

Return type:

function

tail(stack_name, cancel, log_func=<staticmethod object>, sleep_time=5, include_initial=True)[source]

Show and then tail the event log

tail_stack(stack, cancel, log_func=None, **kwargs)[source]
update_stack(fqn, template, old_parameters, parameters, tags, force_interactive=False, force_change_set=False, stack_policy=None, **kwargs)[source]

Update a Cloudformation stack.

Parameters:
  • fqn (str) – The fully qualified name of the Cloudformation stack.
  • template (stacker.providers.base.Template) – A Template object to use when updating the stack.
  • old_parameters (list) – A list of dictionaries that defines the parameter list on the existing Cloudformation stack.
  • parameters (list) – A list of dictionaries that defines the parameter list to be applied to the Cloudformation stack.
  • tags (list) – A list of dictionaries that defines the tags that should be applied to the Cloudformation stack.
  • force_interactive (bool) – A flag that indicates whether the update should be interactive. If set to True, interactive mode will be used no matter if the provider is in interactive mode or not. False will follow the behavior of the provider.
  • force_change_set (bool) – A flag that indicates whether the update must be executed with a change set.
  • stack_policy (stacker.providers.base.Template) – A template object representing a stack policy.
class stacker.providers.aws.default.ProviderBuilder(region=None, **kwargs)[source]

Bases: future.types.newobject.newobject

Implements a Memoized ProviderBuilder for the AWS provider.

build(region=None, profile=None)[source]

Get or create the provider for the given region and profile.

stacker.providers.aws.default.ask_for_approval(full_changeset=None, params_diff=None, include_verbose=False)[source]

Prompt the user for approval to execute a change set.

Parameters:
  • full_changeset (list, optional) – A list of the full changeset that will be output if the user specifies verbose.
  • params_diff (list, optional) – A list of DictValue detailing the differences between two parameters returned by stacker.actions.diff.diff_dictionaries()
  • include_verbose (bool, optional) – Boolean for whether or not to include the verbose option
stacker.providers.aws.default.check_tags_contain(actual, expected)[source]

Check if a set of AWS resource tags is contained in another

Every tag key in expected must be present in actual, and have the same value. Extra keys in actual but not in expected are ignored.

Parameters:
  • actual (list) – Set of tags to be verified, usually from the description of a resource. Each item must be a dict containing Key and Value items.
  • expected (list) – Set of tags that must be present in actual (in the same format).
stacker.providers.aws.default.create_change_set(cfn_client, fqn, template, parameters, tags, change_set_type='UPDATE', replacements_only=False, service_role=None)[source]
stacker.providers.aws.default.format_params_diff(params_diff)[source]

Just a wrapper for stacker.actions.diff.format_params_diff for testing purposes.

stacker.providers.aws.default.generate_cloudformation_args(stack_name, parameters, tags, template, capabilities=['CAPABILITY_NAMED_IAM'], change_set_type=None, service_role=None, stack_policy=None, change_set_name=None)[source]

Used to generate the args for common cloudformation API interactions.

This is used for create_stack/update_stack/create_change_set calls in cloudformation.

Parameters:
  • stack_name (str) – The fully qualified stack name in Cloudformation.
  • parameters (list) – A list of dictionaries that defines the parameter list to be applied to the Cloudformation stack.
  • tags (list) – A list of dictionaries that defines the tags that should be applied to the Cloudformation stack.
  • template (stacker.provider.base.Template) – The template object.
  • capabilities (list, optional) – A list of capabilities to use when updating Cloudformation.
  • change_set_type (str, optional) – An optional change set type to use with create_change_set.
  • service_role (str, optional) – An optional service role to use when interacting with Cloudformation.
  • stack_policy (stacker.providers.base.Template) – A template object representing a stack policy.
  • change_set_name (str, optional) – An optional change set name to use with create_change_set.
Returns:

A dictionary of arguments to be used in the Cloudformation API

call.

Return type:

dict

stacker.providers.aws.default.generate_stack_policy_args(stack_policy=None)[source]

Converts a stack policy object into keyword args.

Parameters:stack_policy (stacker.providers.base.Template) – A template object representing a stack policy.
Returns:A dictionary of keyword arguments to be used elsewhere.
Return type:dict
stacker.providers.aws.default.get_change_set_name()[source]

Return a valid Change Set Name.

The name has to satisfy the following regex:
[a-zA-Z][-a-zA-Z0-9]*

And must be unique across all change sets.

stacker.providers.aws.default.get_cloudformation_client(session)[source]
stacker.providers.aws.default.get_output_dict(stack)[source]

Returns a dict of key/values for the outputs for a given CF stack.

Parameters:stack (dict) – The stack object to get outputs from.
Returns:A dictionary with key/values for each output on the stack.
Return type:dict
stacker.providers.aws.default.output_summary(fqn, action, changeset, params_diff, replacements_only=False)[source]

Log a summary of the changeset.

Parameters:
  • fqn (string) – fully qualified name of the stack
  • action (string) – action to include in the log message
  • changeset (list) – AWS changeset
  • params_diff (list) – A list of dictionaries detailing the differences between two parameters returned by stacker.actions.diff.diff_dictionaries()
  • replacements_only (bool, optional) – boolean for whether or not we only want to list replacements
stacker.providers.aws.default.requires_replacement(changeset)[source]

Return the changes within the changeset that require replacement.

Parameters:changeset (list) – List of changes
Returns:A list of changes that require replacement, if any.
Return type:list
stacker.providers.aws.default.s3_fallback(fqn, template, parameters, tags, method, change_set_name=None, service_role=None)[source]
stacker.providers.aws.default.summarize_params_diff(params_diff)[source]
stacker.providers.aws.default.wait_till_change_set_complete(cfn_client, change_set_id, try_count=25, sleep_time=0.5, max_sleep=3)[source]

Checks state of a changeset, returning when it is in a complete state.

Since changesets can take a little bit of time to get into a complete state, we need to poll it until it does so. This will try to get the state try_count times, waiting sleep_time * 2 seconds between each try up to the max_sleep number of seconds. If, after that time, the changeset is not in a complete state it fails. These default settings will wait a little over one minute.

Parameters:
  • cfn_client (botocore.client.CloudFormation) – Used to query cloudformation.
  • change_set_id (str) – The unique changeset id to wait for.
  • try_count (int) – Number of times to try the call.
  • sleep_time (int) – Time to sleep between attempts.
  • max_sleep (int) – Max time to sleep during backoff
Returns:

The response from cloudformation for the describe_change_set

call.

Return type:

dict

Module contents