sceptre package

class sceptre.NullHandler(level=0)[source]

Bases: logging.Handler

emit(record)[source]

Submodules

sceptre.connection_manager module

sceptre.connection_manager

This module implements a ConnectionManager class, which simplifies and manages Boto3 calls.

class sceptre.connection_manager.ConnectionManager(region, profile=None, stack_name=None)[source]

Bases: object

The Connection Manager is used to create boto3 clients for the various AWS services that Sceptre needs to interact with.

Parameters:
  • profile (str) – The AWS credentials profile that should be used.
  • stack_name (str) – The CloudFormation stack name for this connection.
  • region (str) – The region to use.
call(*args, **kwargs)[source]

Makes a thread-safe Boto3 client call.

Equivalent to boto3.client(<service>).<command>(**kwargs).

Parameters:
  • service (str) – The Boto3 service to return a client for.
  • command (str) – The Boto3 command to call.
  • kwargs (dict) – The keyword arguments to supply to <command>.
Returns:

The response from the Boto3 call.

Return type:

dict

sceptre.context module

sceptre.context

This module implements the SceptreContext class which holds details about the paths used in a Sceptre project.

class sceptre.context.SceptreContext(project_path, command_path, user_variables=None, options=None, output_format=None, no_colour=False, ignore_dependencies=False)[source]

Bases: object

SceptreContext is a place that holds data that is relevant to the project, including references to the project paths such as the path to your Sceptre project, templates path, config path, and the default names for your configuration files.

Parameters:
  • project_path (str) – Absolute path to the base sceptre project folder
  • command_path (str) – The relative path to either StackGroup or Stack.
  • user_variables (dict) – Used to replace the value of anyvitem in a Config file with a value defined by the CLI flag or in a YAML variable file
  • options (dict) – The options specified in by the CLI command
  • output_format (str) – Specify the output format. Available formats: [yaml, json]
  • no_colour (bool) – Specify whether colouring should be used in the CLI output
command_path_is_stack()[source]

Returns True if the command path is a file.

Returns:True if the command path is a file
Return type:bool
full_command_path()[source]

Returns the command path in the format: project_path/config_path/command_path.

Returns:The absolute path to the path that will be executed
Return type:str
full_config_path()[source]

Returns the config path in the format: project_path/config_path.

Returns:The absolute path to the config directory
Return type:str
full_templates_path()[source]

Returns the templates path in the format: project_path/templates_path.

Returns:The absolute path to the templates directory
Return type:str

sceptre.exceptions module

exception sceptre.exceptions.CannotUpdateFailedStackError[source]

Bases: sceptre.exceptions.SceptreException

Error raised when a failed stack is updated.

exception sceptre.exceptions.CircularDependenciesError[source]

Bases: sceptre.exceptions.SceptreException

Error raised if there are circular dependencies

exception sceptre.exceptions.ConfigFileNotFoundError[source]

Bases: sceptre.exceptions.SceptreException

Error raised when a config file does not exist.

exception sceptre.exceptions.DependencyStackMissingOutputError[source]

Bases: sceptre.exceptions.SceptreException

Error raised if a dependency stack does not have the correct outputs.

exception sceptre.exceptions.DependencyStackNotLaunchedError[source]

Bases: sceptre.exceptions.SceptreException

Error raised when a dependency stack has not been launched

exception sceptre.exceptions.InvalidAWSCredentialsError[source]

Bases: sceptre.exceptions.SceptreException

Error raised when AWS credentials are invalid.

exception sceptre.exceptions.InvalidConfigFileError[source]

Bases: sceptre.exceptions.SceptreException

Error raised when a config file lacks mandatory keys.

exception sceptre.exceptions.InvalidHookArgumentSyntaxError[source]

Bases: sceptre.exceptions.SceptreException

Error raised if a hook’s argument syntax is invalid.

exception sceptre.exceptions.InvalidHookArgumentTypeError[source]

Bases: sceptre.exceptions.SceptreException

Error raised if a hook’s argument type is invalid.

exception sceptre.exceptions.InvalidHookArgumentValueError[source]

Bases: sceptre.exceptions.SceptreException

Error raised if a hook’s argument value is invalid.

exception sceptre.exceptions.InvalidSceptreDirectoryError[source]

Bases: sceptre.exceptions.SceptreException

Error raised if a sceptre directory is invalid.

exception sceptre.exceptions.PathConversionError[source]

Bases: sceptre.exceptions.SceptreException

Error raised when a path is unable to be converted.

exception sceptre.exceptions.ProjectAlreadyExistsError[source]

Bases: sceptre.exceptions.SceptreException

Error raised when Sceptre project already exists.

exception sceptre.exceptions.ProtectedStackError[source]

Bases: sceptre.exceptions.SceptreException

Error raised upon execution of an action under active protection

exception sceptre.exceptions.RetryLimitExceededError[source]

Bases: sceptre.exceptions.SceptreException

Error raised if the request limit is exceeded.

exception sceptre.exceptions.SceptreException[source]

Bases: exceptions.Exception

Base class for all Sceptre errors

exception sceptre.exceptions.StackDoesNotExistError[source]

Bases: sceptre.exceptions.SceptreException

Error raised when a stack does not exist.

exception sceptre.exceptions.TemplateSceptreHandlerError[source]

Bases: sceptre.exceptions.SceptreException

Error raised if sceptre_handler() is not defined correctly in the template.

exception sceptre.exceptions.UnknownHookTypeError[source]

Bases: sceptre.exceptions.SceptreException

Error raised if an unrecognised hook type is received.

exception sceptre.exceptions.UnknownStackChangeSetStatusError[source]

Bases: sceptre.exceptions.SceptreException

Error raised if an unknown stack change set status is received.

exception sceptre.exceptions.UnknownStackStatusError[source]

Bases: sceptre.exceptions.SceptreException

Error raised if an unknown stack status is received.

exception sceptre.exceptions.UnsupportedTemplateFileTypeError[source]

Bases: sceptre.exceptions.SceptreException

Error raised if an unsupported template file type is used.

exception sceptre.exceptions.VersionIncompatibleError[source]

Bases: sceptre.exceptions.SceptreException

Error raised if configuration incompatible with running version.

sceptre.helpers module

sceptre.helpers.get_external_stack_name(project_code, stack_name)[source]

Returns the name given to a stack in CloudFormation. :param project_code: The project code, as defined in config.yaml. :type project_code: str :param stack_name: The name of the stack. :type stack_name: str :returns: The name given to the stack in CloudFormation. :rtype: str

sceptre.helpers.mask_key(key)[source]

Returns an masked version of key.

Returned version has all but the last four characters are replaced with the character “*”.

Parameters:key (str) – The string to mask.
Returns:An masked version of the key
Return type:str
sceptre.helpers.normalise_path(path)[source]

Converts a path to use correct path separator. Raises an PathConversionError if the path has a trailing slash. :param path: A directory path :type path: str :raises: sceptre.exceptions.PathConversionError :returns: A normalised path with forward slashes. :returns: string

sceptre.helpers.sceptreise_path(path)[source]

Converts a path to use correct sceptre path separator. Raises an PathConversionError if the path has a trailing slash. :param path: A directory path :type path: str :raises: sceptre.exceptions.PathConversionError :returns: A normalised path with forward slashes. :returns: string

sceptre.stack module

sceptre.stack

This module implements a Stack class, which stores a Stack’s data.

class sceptre.stack.Stack(name, project_code, template_path, region, template_bucket_name=None, template_key_prefix=None, required_version=None, parameters=None, sceptre_user_data=None, hooks=None, s3_details=None, dependencies=None, role_arn=None, protected=False, tags=None, external_name=None, notifications=None, on_failure=None, profile=None, stack_timeout=0, stack_group_config={})[source]

Bases: object

Stack stores information about a particular CloudFormation Stack.

Parameters:
  • name – The name of the Stack.
  • project_code (str) – A code which is prepended to the Stack names of all Stacks built by Sceptre.
  • template_path (str) – The relative path to the CloudFormation, Jinja2 or Python template to build the Stack from.
  • region (str) – The AWS region to build Stacks in.
  • template_bucket_name (str) – The name of the S3 bucket the Template is uploaded to.
  • template_key_prefix (str) – A prefix to the key used to store templates uploaded to S3
  • required_version (str) – A PEP 440 compatible version specifier. If the Sceptre version does not fall within the given version requirement it will abort.
  • parameters (dict) – The keys must match up with the name of the parameter. The value must be of the type as defined in the template.
  • sceptre_user_data (dict) – Data passed into sceptre_handler(sceptre_user_data) function in Python templates or accessible under sceptre_user_data variable within Jinja2 templates.
  • hooks (sceptre.hooks.Hook) – A list of arbitrary shell or python commands or scripts to run.
  • s3_details (dict) –
  • dependencies (list) – The relative path to the Stack, including the file extension of the Stack.
  • role_arn (str) – The ARN of a CloudFormation Service Role that is assumed by CloudFormation to create, update or delete resources.
  • protected (bool) – Stack protection against execution.
  • tags (dict) – CloudFormation Tags to be applied to the Stack.
  • external_name (str) –
  • notifications (list) – SNS topic ARNs to publish Stack related events to. A maximum of 5 ARNs can be specified per Stack.
  • on_failure (str) – This parameter describes the action taken by CloudFormation when a Stack fails to create.
  • profile (str) – The name of the profile as defined in ~/.aws/config and ~/.aws/credentials.
  • stack_timeout (int) – A timeout in minutes before considering the Stack deployment as failed. After the specified timeout, the Stack will be rolled back. Specifiyng zero, as well as ommiting the field, will result in no timeout. Supports only positive integer value.
  • stack_group_config (dict) – The StackGroup config for the Stack
connection_manager
Returns ConnectionManager.
returns:ConnectionManager.
Return type:ConnectionManager
hooks

This is a descriptor class used to store an attribute that may contain Hook objects. Used to setup Hooks when added as a attribute. Supports nested dictionary and lists.

Parameters:name (str) – Attribute suffix used to store the property in the instance.
notifications = None
parameters = None
sceptre_user_data

Returns sceptre_user_data after ensuring that it is fully resolved.

Return type:dict or list or None
template

Returns the CloudFormation Template used to create the Stack.

Returns:The Stack’s template.
Return type:str

sceptre.stack_status module

sceptre.stack_status

This module implemets structs for simplified Stack status and simplified ChangeSet status values.

class sceptre.stack_status.StackChangeSetStatus[source]

Bases: object

StackChangeSetStatus stores simplified ChangeSet statuses.

DEFUNCT = 'defunct'
PENDING = 'pending'
READY = 'ready'
class sceptre.stack_status.StackStatus[source]

Bases: object

StackStatus stores simplified Stack statuses.

COMPLETE = 'complete'
FAILED = 'failed'
IN_PROGRESS = 'in progress'
PENDING = 'pending'

sceptre.stack_status_colourer module

sceptre.stack_status_colourer

This module implements a StackStatusColourer class, colours any Stack Statuses found in a given string.

class sceptre.stack_status_colourer.StackStatusColourer[source]

Bases: object

StackStatusColourer adds colours to stack statuses.

STACK_STATUS_CODES = {'UPDATE_COMPLETE': '\x1b[32m', 'CREATE_COMPLETE': '\x1b[32m', 'DELETE_FAILED': '\x1b[31m', 'DELETE_IN_PROGRESS': '\x1b[33m', 'UPDATE_IN_PROGRESS': '\x1b[33m', 'CREATE_IN_PROGRESS': '\x1b[33m', 'ROLLBACK_IN_PROGRESS': '\x1b[33m', 'CREATE_FAILED': '\x1b[31m', 'DELETE_COMPLETE': '\x1b[32m', 'ROLLBACK_FAILED': '\x1b[31m', 'UPDATE_ROLLBACK_FAILED': '\x1b[31m', 'UPDATE_ROLLBACK_COMPLETE': '\x1b[32m', 'UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS': '\x1b[33m', 'UPDATE_FAILED': '\x1b[31m', 'ROLLBACK_COMPLETE': '\x1b[31m', 'UPDATE_ROLLBACK_IN_PROGRESS': '\x1b[33m', 'PENDING': '\x1b[36m', 'UPDATE_COMPLETE_CLEANUP_IN_PROGRESS': '\x1b[33m'}
STACK_STATUS_PATTERN = <_sre.SRE_Pattern object>
colour(string)[source]

Colours all Stack Statueses in string.

The colours applied are defined in sceptre.stack_status_colourer.StackStatusColourer.STACK_STATUS_CODES

Parameters:string (str) – A string to colour.
Returns:The string with all stack status values coloured.
Return type:str

sceptre.template module

sceptre.template

This module implements a Template class, which stores a CloudFormation template and implements methods for uploading it to S3.

class sceptre.template.Template(path, sceptre_user_data, connection_manager=None, s3_details=None)[source]

Bases: object

Template represents an AWS CloudFormation template. It is responsible for loading, storing and optionally uploading local templates for use by CloudFormation.

Parameters:
  • path (str) – The absolute path to the file which stores the CloudFormation template.
  • sceptre_user_data (dict) – A dictionary of arbitrary data to be passed to a handler function in an external Python script.
  • connection_manager (sceptre.connection_manager.ConnectionManager) –
  • s3_details (dict) –
body

Represents body of the CloudFormation template.

Returns:The body of the CloudFormation template.
Return type:str
get_boto_call_parameter()[source]

Returns the CloudFormation template location.

Uploads the template to S3 and returns the object’s URL, or returns the template itself.

Returns:The boto call parameter for the template.
Return type:dict
upload_to_s3()[source]

Uploads the template to bucket_name and returns its URL.

The Template is uploaded with the bucket_key.

Returns:The URL of the Template object in S3.
Return type:str
Raises:botocore.exceptions.ClientError