Skip to content

create_launch_template async

create_launch_template(
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    dry_run: Optional[Boolean] = None,
    client_token: Optional[String] = None,
    launch_template_name: Optional[String] = None,
    version_description: Optional[VersionDescription] = None,
    launch_template_data: Optional[RequestLaunchTemplateData] = None,
    operator: Optional[OperatorRequest] = None,
    tag_specifications: Optional[TagSpecificationList] = None,
) -> CreateLaunchTemplateResult

Creates a launch template.

A launch template contains the parameters to launch an instance. When you launch an instance using RunInstances, you can specify a launch template instead of providing the launch parameters in the request. For more information, see Store instance launch parameters in Amazon EC2 launch templates in the Amazon EC2 User Guide.

To clone an existing launch template as the basis for a new launch template, use the Amazon EC2 console. The API, SDKs, and CLI do not support cloning a template. For more information, see Create a launch template from an existing launch template 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_name (Optional[String], default: None ) –

    A name for the launch template.

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

    A description for the first version of the launch template.

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

    The information for the launch template.

  • operator (Optional[OperatorRequest], default: None ) –

    Reserved for internal use.

  • tag_specifications (Optional[TagSpecificationList], default: None ) –

    The tags to apply to the launch template on creation. To tag the launch template, the resource type must be launch-template.

    To specify the tags for the resources that are created when an instance is launched, you must use the TagSpecifications parameter in the launch template data structure.

Raises:

Examples:

To create a launch template This example creates a launch template that specifies the subnet in which to launch the instance, assigns a public IP address and an IPv6 address to the instance, and creates a tag for the instance.

>>> await client.create_launch_template(launch_template_name='my-template', version_description='WebVersion1', launch_template_data={'NetworkInterfaces': [{'AssociatePublicIpAddress': True, 'DeviceIndex': 0, 'Ipv6AddressCount': 1, 'SubnetId': 'subnet-7b16de0c'}], 'ImageId': 'ami-8c1be5f6', 'InstanceType': 't2.small', 'TagSpecifications': [{'ResourceType': 'instance', 'Tags': [{'Key': 'Name', 'Value': 'webserver'}]}]})
Source code in docs_src/capo_ec2/_services/async_ec2.py
async def create_launch_template(
    self,
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
    client_token: Optional["capo_ec2.types.string.String"] = None,
    launch_template_name: 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,
    operator: Optional["capo_ec2.types.operator_request.OperatorRequest"] = None,
    tag_specifications: Optional[
        "capo_ec2.types.tag_specification_list.TagSpecificationList"
    ] = None,
) -> "capo_ec2.types.create_launch_template_result.CreateLaunchTemplateResult":
    """<p>Creates a launch template.</p> <p>A launch template contains the parameters to launch an instance. When you launch an instance using <a>RunInstances</a>, you can specify a launch template instead of providing the launch parameters in the request. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-launch-templates.html">Store instance launch parameters in Amazon EC2 launch templates</a> in the <i>Amazon EC2 User Guide</i>.</p> <p>To clone an existing launch template as the basis for a new launch template, use the Amazon EC2 console. The API, SDKs, and CLI do not support cloning a template. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/create-launch-template.html#create-launch-template-from-existing-launch-template">Create a launch template from an existing launch template</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_name: <p>A name for the launch template.</p>
        version_description: <p>A description for the first version of the launch template.</p>
        launch_template_data: <p>The information for the launch template.</p>
        operator: <p>Reserved for internal use.</p>
        tag_specifications: <p>The tags to apply to the launch template on creation. To tag the launch template, the resource type must be <code>launch-template</code>.</p> <p>To specify the tags for the resources that are created when an instance is launched, you must use the <code>TagSpecifications</code> parameter in the <a href="https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RequestLaunchTemplateData.html">launch template data</a> structure.</p>

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

    Examples:
        To create a launch template
        This example creates a launch template that specifies the subnet in which to launch the instance, assigns a public IP address and an IPv6 address to the instance, and creates a tag for the instance.

        >>> await client.create_launch_template(launch_template_name='my-template', version_description='WebVersion1', launch_template_data={'NetworkInterfaces': [{'AssociatePublicIpAddress': True, 'DeviceIndex': 0, 'Ipv6AddressCount': 1, 'SubnetId': 'subnet-7b16de0c'}], 'ImageId': 'ami-8c1be5f6', 'InstanceType': 't2.small', 'TagSpecifications': [{'ResourceType': 'instance', 'Tags': [{'Key': 'Name', 'Value': 'webserver'}]}]})
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_ec2.types.create_launch_template_request.CreateLaunchTemplateRequest]",
    ) -> AsyncOperationResponse[
        "capo_ec2.types.create_launch_template_result.CreateLaunchTemplateResult"
    ]:
        import capo_ec2._operations.amazon_ec2.create_launch_template

        (
            output,
            http_response,
        ) = await capo_ec2._operations.amazon_ec2.create_launch_template.async_create_launch_template(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

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

        return capo_ec2.types.create_launch_template_request.redact_sensitive(
            input_
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("CreateLaunchTemplate", redact_input=_redact_input),
    )
    input_: capo_ec2.types.create_launch_template_request.CreateLaunchTemplateRequest = {}
    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_name is not None:
        input_["launch_template_name"] = launch_template_name
    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 operator is not None:
        input_["operator"] = operator
    if tag_specifications is not None:
        input_["tag_specifications"] = tag_specifications

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output