InitPackage

class aws_cdk.aws_ec2.InitPackage(type, versions, package_name=None, service_handles=None)

Bases: aws_cdk.aws_ec2.InitElement

A package to be installed during cfn-init time.

Example:

# vpc is of type Vpc
# instance_type is of type InstanceType
# machine_image is of type IMachineImage


ec2.Instance(self, "Instance",
    vpc=vpc,
    instance_type=instance_type,
    machine_image=machine_image,

    # Showing the most complex setup, if you have simpler requirements
    # you can use `CloudFormationInit.fromElements()`.
    init=ec2.CloudFormationInit.from_config_sets(
        config_sets={
            # Applies the configs below in this order
            "default": ["yumPreinstall", "config"]
        },
        configs={
            "yum_preinstall": ec2.InitConfig([
                # Install an Amazon Linux package using yum
                ec2.InitPackage.yum("git")
            ]),
            "config": ec2.InitConfig([
                # Create a JSON file from tokens (can also create other files)
                ec2.InitFile.from_object("/etc/stack.json", {
                    "stack_id": Stack.of(self).stack_id,
                    "stack_name": Stack.of(self).stack_name,
                    "region": Stack.of(self).region
                }),

                # Create a group and user
                ec2.InitGroup.from_name("my-group"),
                ec2.InitUser.from_name("my-user"),

                # Install an RPM from the internet
                ec2.InitPackage.rpm("http://mirrors.ukfast.co.uk/sites/dl.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/r/rubygem-git-1.5.0-2.el8.noarch.rpm")
            ])
        }
    ),
    init_options=ec2.ApplyCloudFormationInitOptions(
        # Optional, which configsets to activate (['default'] by default)
        config_sets=["default"],

        # Optional, how long the installation is expected to take (5 minutes by default)
        timeout=Duration.minutes(30),

        # Optional, whether to include the --url argument when running cfn-init and cfn-signal commands (false by default)
        include_url=True,

        # Optional, whether to include the --role argument when running cfn-init and cfn-signal commands (false by default)
        include_role=True
    )
)
Parameters
  • type (str) –

  • versions (Sequence[str]) –

  • package_name (Optional[str]) –

  • service_handles (Optional[Sequence[InitServiceRestartHandle]]) –

Attributes

element_type

Returns the init element type for this element.

Return type

str

Static Methods

classmethod apt(package_name, *, service_restart_handles=None, version=None)

Install a package using APT.

Parameters
  • package_name (str) –

  • service_restart_handles (Optional[Sequence[InitServiceRestartHandle]]) – Restart the given services after this command has run. Default: - Do not restart any service

  • version (Optional[Sequence[str]]) – Specify the versions to install. Default: - Install the latest version

Return type

InitPackage

classmethod msi(location, *, key=None, service_restart_handles=None)

Install an MSI package from an HTTP URL or a location on disk.

Parameters
  • location (str) –

  • key (Optional[str]) – Identifier key for this package. You can use this to order package installs. Default: - Automatically generated

  • service_restart_handles (Optional[Sequence[InitServiceRestartHandle]]) – Restart the given service after this command has run. Default: - Do not restart any service

Return type

InitPackage

classmethod python(package_name, *, service_restart_handles=None, version=None)

Install a package from PyPI.

Parameters
  • package_name (str) –

  • service_restart_handles (Optional[Sequence[InitServiceRestartHandle]]) – Restart the given services after this command has run. Default: - Do not restart any service

  • version (Optional[Sequence[str]]) – Specify the versions to install. Default: - Install the latest version

Return type

InitPackage

classmethod rpm(location, *, key=None, service_restart_handles=None)

Install an RPM from an HTTP URL or a location on disk.

Parameters
  • location (str) –

  • key (Optional[str]) – Identifier key for this package. You can use this to order package installs. Default: - Automatically generated

  • service_restart_handles (Optional[Sequence[InitServiceRestartHandle]]) – Restart the given service after this command has run. Default: - Do not restart any service

Return type

InitPackage

classmethod ruby_gem(gem_name, *, service_restart_handles=None, version=None)

Install a package from RubyGems.

Parameters
  • gem_name (str) –

  • service_restart_handles (Optional[Sequence[InitServiceRestartHandle]]) – Restart the given services after this command has run. Default: - Do not restart any service

  • version (Optional[Sequence[str]]) – Specify the versions to install. Default: - Install the latest version

Return type

InitPackage

classmethod yum(package_name, *, service_restart_handles=None, version=None)

Install a package using Yum.

Parameters
  • package_name (str) –

  • service_restart_handles (Optional[Sequence[InitServiceRestartHandle]]) – Restart the given services after this command has run. Default: - Do not restart any service

  • version (Optional[Sequence[str]]) – Specify the versions to install. Default: - Install the latest version

Return type

InitPackage