canned

Canned Template implements the parameterized template creation logic. It allows developer to add more custom logic before or after the template creation.

troposphere_mate.core.canned.helper_fn_sub(text, *params)[source]

A helper function to construct FnSub snippet easily. It uses python str.format place holder {}, it will be replaced with parameters substitution. For example, helper_fn_sub("{}-my-ec2-instance", param_env_name) will be translate to this. The param_env_name is the EnvName template parameter:

{
    "Fn::Sub": [
        "${EnvName}-my-ec2-instance"
        {
            "EnvName": {
                "Ref": {
                    "EnvName"
                }
            }
        }
    ]
}
class troposphere_mate.core.canned.Canned(metadata=None, **kwargs)[source]

Represent a Canned CloudFormation Template. Defines the creation logic and parameters of a Template. It is a Factory Class for Template.

Parameters:
  • logic_id (str) – logic id of this template been used in the master template as a nested template
  • root_dir (str) – dir path of where the template file been created
  • metadata – relative path of where the template file been created

中文文档

Canned 的英文是 罐装的. 这里是表示, 此类是一个 Template 的罐头, 类本身实际是一个 configirl.ConfigClass 的子类, 能对配置数据进行管理. 而通过 def create_template() 方法定义了基于配置数据创建 troposphere_mate.Template 实例的逻辑. 也就是说, 创建 Canned 实例时, 只读取配置数据, 并没有真正创建 Template 实例.

此类实现了对 Template 的复用. 比如你定义了一个 VPC Tier 的 Template, 里面包含 VPC, Subnet 等资源, 而你可以通过更新配置数据的方式, 复用该模板.

之所以在 Template 之外进行一层包装, 是因为在创建 Template 的实例过程中需要执行必要的 validation. 而我们定义可复用模板时, 必然所有的 Resources Properties 都是参数化的, 换言之, 定义时还未可知. 所以我们要将配置参数和创建模板分离开.

class troposphere_mate.core.canned.MultiEnvBasicConfig(metadata=None, **kwargs)[source]

A multi environment / stage config settings.

中文文档

一个常用的 Multi Stage / Environment 的配置模板.

post_create_template_hooker(**kwargs)[source]

Automatically update common tags after the template been created.

class troposphere_mate.core.canned.ServerlessConfig(metadata=None, **kwargs)[source]

Serverless application config settings for common fields.

S3_PREFIX_LAMBDA_ARTIFACT = Constant(name='S3_PREFIX_LAMBDA_ARTIFACT', value=<NOTHING>)

usually it is lambda/{github_account_username}/{github_repo_name}. The final source code s3 key is lambda/{github_account_username}/{github_repo_name}/{version}/source.zip run make lbd-info command to get more information

LAMBDA_LATEST_LAYER_ARNS = Derivable(name='LAMBDA_LATEST_LAYER_ARNS', value=<NOTHING>)

Latest lambda layer arn for awslambda.Function.Layers property