Skip to content

create_launch_template_version

create_launch_template_version(
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    dry_run: Optional[Boolean] = None,
    client_token: Optional[String] = None,
    launch_template_id: Optional[LaunchTemplateId] = None,
    launch_template_name: Optional[LaunchTemplateName] = None,
    source_version: Optional[String] = None,
    version_description: Optional[VersionDescription] = None,
    launch_template_data: Optional[RequestLaunchTemplateData] = None,
    resolve_alias: Optional[Boolean] = None,
) -> CreateLaunchTemplateVersionResult

Creates a new version of a launch template. You must specify an existing launch template, either by name or ID. You can determine whether the new version inherits parameters from a source version, and add or overwrite parameters as needed.

Launch template versions are numbered in the order in which they are created. You can't specify, change, or replace the numbering of launch template versions.

Launch templates are immutable; after you create a launch template, you can't modify it. Instead, you can create a new version of the launch template that includes the changes that you require.

For more information, see Modify a launch template (manage launch template versions) in the Amazon EC2 User Guide.

Parameters:

  • dry_run (Optional[Boolean], default: None ) –

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

  • client_token (Optional[String], default: None ) –

    Unique, case-sensitive identifier you provide to ensure the idempotency of the request. If a client token isn't specified, a randomly generated token is used in the request to ensure idempotency.

    For more information, see Ensuring idempotency.

    Constraint: Maximum 128 ASCII characters.

  • launch_template_id (Optional[LaunchTemplateId], default: None ) –

    The ID of the launch template.

    You must specify either the launch template ID or the launch template name, but not both.

  • launch_template_name (Optional[LaunchTemplateName], default: None ) –

    The name of the launch template.

    You must specify either the launch template ID or the launch template name, but not both.

  • source_version (Optional[String], default: None ) –

    The version of the launch template on which to base the new version. Snapshots applied to the block device mapping are ignored when creating a new version unless they are explicitly included.

    If you specify this parameter, the new version inherits the launch parameters from the source version. If you specify additional launch parameters for the new version, they overwrite any corresponding launch parameters inherited from the source version.

    If you omit this parameter, the new version contains only the launch parameters that you specify for the new version.

  • version_description (Optional[VersionDescription], default: None ) –

    A description for the version of the launch template.

  • launch_template_data (Optional[RequestLaunchTemplateData], default: None ) –

    The information for the launch template.

  • resolve_alias (Optional[Boolean], default: None ) –

    If true, and if a Systems Manager parameter is specified for ImageId, the AMI ID is displayed in the response for imageID. For more information, see Use a Systems Manager parameter instead of an AMI ID in the Amazon EC2 User Guide.

    Default: false

Raises:

Examples:

To create a launch template version This example creates a new launch template version based on version 1 of the specified launch template and specifies a different AMI ID.

>>> client.create_launch_template_version(launch_template_id='lt-0abcd290751193123', source_version='1', version_description='WebVersion2', launch_template_data={'ImageId': 'ami-c998b6b2'})
Source code in docs_src/capo_ec2/_services/ec2.py
def create_launch_template_version(
    self,
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
    client_token: Optional["capo_ec2.types.string.String"] = None,
    launch_template_id: Optional[
        "capo_ec2.types.launch_template_id.LaunchTemplateId"
    ] = None,
    launch_template_name: Optional[
        "capo_ec2.types.launch_template_name.LaunchTemplateName"
    ] = None,
    source_version: Optional["capo_ec2.types.string.String"] = None,
    version_description: Optional[
        "capo_ec2.types.version_description.VersionDescription"
    ] = None,
    launch_template_data: Optional[
        "capo_ec2.types.request_launch_template_data.RequestLaunchTemplateData"
    ] = None,
    resolve_alias: Optional["capo_ec2.types.boolean.Boolean"] = None,
) -> "capo_ec2.types.create_launch_template_version_result.CreateLaunchTemplateVersionResult":
    """<p>Creates a new version of a launch template. You must specify an existing launch template, either by name or ID. You can determine whether the new version inherits parameters from a source version, and add or overwrite parameters as needed.</p> <p>Launch template versions are numbered in the order in which they are created. You can't specify, change, or replace the numbering of launch template versions.</p> <p>Launch templates are immutable; after you create a launch template, you can't modify it. Instead, you can create a new version of the launch template that includes the changes that you require.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/manage-launch-template-versions.html">Modify a launch template (manage launch template versions)</a> in the <i>Amazon EC2 User Guide</i>.</p>

    Args:
        dry_run: <p>Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is <code>DryRunOperation</code>. Otherwise, it is <code>UnauthorizedOperation</code>.</p>
        client_token: <p>Unique, case-sensitive identifier you provide to ensure the idempotency of the request. If a client token isn't specified, a randomly generated token is used in the request to ensure idempotency.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html">Ensuring idempotency</a>.</p> <p>Constraint: Maximum 128 ASCII characters.</p>
        launch_template_id: <p>The ID of the launch template.</p> <p>You must specify either the launch template ID or the launch template name, but not both.</p>
        launch_template_name: <p>The name of the launch template.</p> <p>You must specify either the launch template ID or the launch template name, but not both.</p>
        source_version: <p>The version of the launch template on which to base the new version. Snapshots applied to the block device mapping are ignored when creating a new version unless they are explicitly included.</p> <p>If you specify this parameter, the new version inherits the launch parameters from the source version. If you specify additional launch parameters for the new version, they overwrite any corresponding launch parameters inherited from the source version.</p> <p>If you omit this parameter, the new version contains only the launch parameters that you specify for the new version.</p>
        version_description: <p>A description for the version of the launch template.</p>
        launch_template_data: <p>The information for the launch template.</p>
        resolve_alias: <p>If <code>true</code>, and if a Systems Manager parameter is specified for <code>ImageId</code>, the AMI ID is displayed in the response for <code>imageID</code>. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/create-launch-template.html#use-an-ssm-parameter-instead-of-an-ami-id">Use a Systems Manager parameter instead of an AMI ID</a> in the <i>Amazon EC2 User Guide</i>.</p> <p>Default: <code>false</code> </p>

    Raises:
        capo_ec2.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To create a launch template version
        This example creates a new launch template version based on version 1 of the specified launch template and specifies a different AMI ID.

        >>> client.create_launch_template_version(launch_template_id='lt-0abcd290751193123', source_version='1', version_description='WebVersion2', launch_template_data={'ImageId': 'ami-c998b6b2'})
    """

    def _handler(
        req: "OperationRequest[capo_ec2.types.create_launch_template_version_request.CreateLaunchTemplateVersionRequest]",
    ) -> OperationResponse[
        "capo_ec2.types.create_launch_template_version_result.CreateLaunchTemplateVersionResult"
    ]:
        import capo_ec2._operations.amazon_ec2.create_launch_template_version

        output, http_response = (
            capo_ec2._operations.amazon_ec2.create_launch_template_version.create_launch_template_version(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_ec2.types.create_launch_template_version_request.CreateLaunchTemplateVersionRequest",
    ) -> dict[str, Any]:
        import capo_ec2.types.create_launch_template_version_request

        return (
            capo_ec2.types.create_launch_template_version_request.redact_sensitive(
                input_
            )
        )

    def _redact_output(
        output: "capo_ec2.types.create_launch_template_version_result.CreateLaunchTemplateVersionResult",
    ) -> dict[str, Any]:
        import capo_ec2.types.create_launch_template_version_result

        return (
            capo_ec2.types.create_launch_template_version_result.redact_sensitive(
                output
            )
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "CreateLaunchTemplateVersion",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_ec2.types.create_launch_template_version_request.CreateLaunchTemplateVersionRequest = {}
    if dry_run is not None:
        input_["dry_run"] = dry_run
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    if launch_template_id is not None:
        input_["launch_template_id"] = launch_template_id
    if launch_template_name is not None:
        input_["launch_template_name"] = launch_template_name
    if source_version is not None:
        input_["source_version"] = source_version
    if version_description is not None:
        input_["version_description"] = version_description
    if launch_template_data is not None:
        input_["launch_template_data"] = launch_template_data
    if resolve_alias is not None:
        input_["resolve_alias"] = resolve_alias

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output