CloudFormationInit

class aws_cdk.aws_ec2.CloudFormationInit(*args, **kwargs)

Bases: object

A CloudFormation-init configuration.

Methods

add_config(config_name, config)

Add a config with the given name to this CloudFormationInit object.

Parameters
Return type

None

add_config_set(config_set_name, config_names=None)

Add a config set with the given name to this CloudFormationInit object.

The new configset will reference the given configs in the given order.

Parameters
  • config_set_name (str) –

  • config_names (Optional[List[str]]) –

Return type

None

attach(attached_resource, *, instance_role, platform, user_data, config_sets=None, embed_fingerprint=None, ignore_failures=None, print_log=None)

Attach the CloudFormation Init config to the given resource.

As an app builder, use instance.applyCloudFormationInit() or autoScalingGroup.applyCloudFormationInit() to trigger this method.

This method does the following:

  • Renders the AWS::CloudFormation::Init object to the given resource’s metadata, potentially adding a AWS::CloudFormation::Authentication object next to it if required.

  • Updates the instance role policy to be able to call the APIs required for cfn-init and cfn-signal to work, and potentially add permissions to download referenced asset and bucket resources.

  • Updates the given UserData with commands to execute the cfn-init script.

Parameters
  • attached_resource (CfnResource) –

  • instance_role (IRole) – Instance role of the consuming instance or fleet.

  • platform (OperatingSystemType) – OS Platform the init config will be used for.

  • user_data (UserData) – UserData to add commands to.

  • config_sets (Optional[List[str]]) – ConfigSet to activate. Default: [‘default’]

  • embed_fingerprint (Optional[bool]) – Whether to embed a hash into the userData. If true (the default), a hash of the config will be embedded into the UserData, so that if the config changes, the UserData changes and the instance will be replaced. If false, no such hash will be embedded, and if the CloudFormation Init config changes nothing will happen to the running instance. Default: true

  • ignore_failures (Optional[bool]) – Don’t fail the instance creation when cfn-init fails. You can use this to prevent CloudFormation from rolling back when instances fail to start up, to help in debugging. Default: false

  • print_log (Optional[bool]) – Print the results of running cfn-init to the Instance System Log. By default, the output of running cfn-init is written to a log file on the instance. Set this to true to print it to the System Log (visible from the EC2 Console), false to not print it. (Be aware that the system log is refreshed at certain points in time of the instance life cycle, and successful execution may not always show up). Default: true

Return type

None

Static Methods

classmethod from_config(config)

Use an existing InitConfig object as the default and only config.

Parameters

config (InitConfig) –

Return type

CloudFormationInit

classmethod from_config_sets(*, configs, config_sets)

Build a CloudFormationInit from config sets.

Parameters
  • configs (Mapping[str, InitConfig]) – The sets of configs to pick from.

  • config_sets (Mapping[str, List[str]]) – The definitions of each config set.

Return type

CloudFormationInit

classmethod from_elements(*elements)

Build a new config from a set of Init Elements.

Parameters

elements (InitElement) –

Return type

CloudFormationInit