Skip to content

import_vm_image

import_vm_image(
    name: NonEmptyString,
    semantic_version: VersionNumber,
    platform: Platform,
    vm_import_task_id: NonEmptyString,
    client_token: ClientToken,
    *,
    config_overrides: Optional[imagebuilderClientConfig] = None,
    description: Optional[NonEmptyString] = None,
    os_version: Optional[OsVersion] = None,
    logging_configuration: Optional[ImageLoggingConfiguration] = None,
    tags: Optional[TagMap] = None,
) -> ImportVmImageResponse

Creates an Image Builder image resource from an Amazon EC2 VM import task. The response returns as soon as Image Builder creates the image resource in the PENDING state. Image Builder then monitors the import task asynchronously. When the task completes, Image Builder records the AMI that it produced as the new image's output resource and marks the image AVAILABLE. You can then use the imported image as the base image for your recipes.

To create the VM import task, use the Amazon EC2 API ImportImage operation, or the import-image CLI command.

Parameters:

  • name (NonEmptyString) –

    The name of the base image that is created by the import process. Image Builder generates the image ARN from a normalized form of the name, so names that differ only in case, spaces, or underscores count as the same name. If an image with the same name and semantic version already exists in your account in the same Amazon Web Services Region, the import creates a new build version for it.

  • semantic_version (VersionNumber) –

    The semantic version to attach to the base image that was created during the import process. This version follows the semantic version syntax.

    The semantic version has four nodes: ../. You can assign values for the first three, and can filter on all of them.

    Assignment: For the first three nodes, you can assign any positive integer value, including zero. The upper limit is 2^30-1, or 1073741823, for each node. Image Builder automatically assigns the build number to the fourth node.

    Patterns: You can use any numeric pattern that adheres to the assignment requirements for the nodes that you can assign. For example, you might choose a software version pattern, such as 1.0.0, or a date, such as 2021.01.01.

  • description (Optional[NonEmptyString], default: None ) –

    The description for the base image that is created by the import process.

  • platform (Platform) –

    The operating system platform for the imported VM.

  • os_version (Optional[OsVersion], default: None ) –

    The operating system version for the imported VM.

  • vm_import_task_id (NonEmptyString) –

    The importTaskId (API) or ImportTaskId (CLI) from the Amazon EC2 VM import process. The import task doesn't need to be complete when you call ImportVmImage - Image Builder monitors the task and finishes creating the image when the task completes.

  • logging_configuration (Optional[ImageLoggingConfiguration], default: None ) –

    The CloudWatch Logs log group where Image Builder sends the import logs. For ImportVmImage, the log group name must be within the /aws/imagebuilder/ namespace.

  • tags (Optional[TagMap], default: None ) –

    Tags that are attached to the import resources.

  • client_token (ClientToken) –

    A unique, case-sensitive identifier you provide to ensure that the operation runs no more than one time. If you retry a request with the same client token, Image Builder returns the original response without running the operation again. For more information, see Ensuring idempotency in the Amazon EC2 API Reference.

Raises:

  • ClientException –

    A generic client error. This error usually indicates that the request failed a validation check, such as when a downstream service rejects a configured value.

  • ServiceException –

    An internal server error occurred while Image Builder processed the request. Retrying the request may succeed.

  • ServiceUnavailableException –

    The service is unable to process your request at this time.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Examples:

Import a virtual machine as an Image Builder image The following example registers the output of an EC2 VM Import/Export task (import-ami) as a new Image Builder image, so you can use the imported virtual machine as a base image.

>>> client.import_vm_image(name='my-example-imported-image', semantic_version='1.0.0', platform='Linux', os_version='Amazon Linux 2', vm_import_task_id='import-ami-1234567890abcdef0', client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLE00000')
Source code in docs_src/capo_imagebuilder/_services/imagebuilder.py
def import_vm_image(
    self,
    name: "capo_imagebuilder.types.non_empty_string.NonEmptyString",
    semantic_version: "capo_imagebuilder.types.version_number.VersionNumber",
    platform: "capo_imagebuilder.types.platform.Platform",
    vm_import_task_id: "capo_imagebuilder.types.non_empty_string.NonEmptyString",
    client_token: "capo_imagebuilder.types.client_token.ClientToken",
    *,
    config_overrides: Optional[imagebuilderClientConfig] = None,
    description: Optional[
        "capo_imagebuilder.types.non_empty_string.NonEmptyString"
    ] = None,
    os_version: Optional["capo_imagebuilder.types.os_version.OsVersion"] = None,
    logging_configuration: Optional[
        "capo_imagebuilder.types.image_logging_configuration.ImageLoggingConfiguration"
    ] = None,
    tags: Optional["capo_imagebuilder.types.tag_map.TagMap"] = None,
) -> "capo_imagebuilder.types.import_vm_image_response.ImportVmImageResponse":
    """<p>Creates an Image Builder image resource from an Amazon EC2 VM import task. The response returns as soon as Image Builder creates the image resource in the <code>PENDING</code> state. Image Builder then monitors the import task asynchronously. When the task completes, Image Builder records the AMI that it produced as the new image's output resource and marks the image <code>AVAILABLE</code>. You can then use the imported image as the base image for your recipes.</p> <p>To create the VM import task, use the Amazon EC2 API <a href="https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_ImportImage.html">ImportImage</a> operation, or the <a href="https://docs.aws.amazon.com/cli/latest/reference/ec2/import-image.html">import-image</a> CLI command.</p>

    Args:
        name: <p>The name of the base image that is created by the import process. Image Builder generates the image ARN from a normalized form of the name, so names that differ only in case, spaces, or underscores count as the same name. If an image with the same name and semantic version already exists in your account in the same Amazon Web Services Region, the import creates a new build version for it.</p>
        semantic_version: <p>The semantic version to attach to the base image that was created during the import process. This version follows the semantic version syntax.</p> <note> <p>The semantic version has four nodes: <major>.<minor>.<patch>/<build>. You can assign values for the first three, and can filter on all of them.</p> <p> <b>Assignment:</b> For the first three nodes, you can assign any positive integer value, including zero. The upper limit is 2^30-1, or 1073741823, for each node. Image Builder automatically assigns the build number to the fourth node.</p> <p> <b>Patterns:</b> You can use any numeric pattern that adheres to the assignment requirements for the nodes that you can assign. For example, you might choose a software version pattern, such as 1.0.0, or a date, such as 2021.01.01.</p> </note>
        description: <p>The description for the base image that is created by the import process.</p>
        platform: <p>The operating system platform for the imported VM.</p>
        os_version: <p>The operating system version for the imported VM.</p>
        vm_import_task_id: <p>The <code>importTaskId</code> (API) or <code>ImportTaskId</code> (CLI) from the Amazon EC2 VM import process. The import task doesn't need to be complete when you call ImportVmImage - Image Builder monitors the task and finishes creating the image when the task completes.</p>
        logging_configuration: <p>The CloudWatch Logs log group where Image Builder sends the import logs. For ImportVmImage, the log group name must be within the <code>/aws/imagebuilder/</code> namespace.</p>
        tags: <p>Tags that are attached to the import resources.</p>
        client_token: <p>A unique, case-sensitive identifier you provide to ensure that the operation runs no more than one time. If you retry a request with the same client token, Image Builder returns the original response without running the operation again. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html">Ensuring idempotency</a> in the <i>Amazon EC2 API Reference</i>.</p>

    Raises:
        capo_imagebuilder.errors.client_exception.ClientException: <p>A generic client error. This error usually indicates that the request failed a validation check, such as when a downstream service rejects a configured value.</p>
        capo_imagebuilder.errors.service_exception.ServiceException: <p>An internal server error occurred while Image Builder processed the request. Retrying the request may succeed.</p>
        capo_imagebuilder.errors.service_unavailable_exception.ServiceUnavailableException: <p>The service is unable to process your request at this time.</p>
        capo_imagebuilder.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        Import a virtual machine as an Image Builder image
        The following example registers the output of an EC2 VM Import/Export task (import-ami) as a new Image Builder image, so you can use the imported virtual machine as a base image.

        >>> client.import_vm_image(name='my-example-imported-image', semantic_version='1.0.0', platform='Linux', os_version='Amazon Linux 2', vm_import_task_id='import-ami-1234567890abcdef0', client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLE00000')
    """

    def _handler(
        req: "OperationRequest[capo_imagebuilder.types.import_vm_image_request.ImportVmImageRequest]",
    ) -> OperationResponse[
        "capo_imagebuilder.types.import_vm_image_response.ImportVmImageResponse"
    ]:
        import capo_imagebuilder._operations.imagebuilder.import_vm_image

        output, http_response = (
            capo_imagebuilder._operations.imagebuilder.import_vm_image.import_vm_image(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("ImportVmImage")
    )
    input_: capo_imagebuilder.types.import_vm_image_request.ImportVmImageRequest = {
        "name": name,
        "semantic_version": semantic_version,
        "platform": platform,
        "vm_import_task_id": vm_import_task_id,
        "client_token": client_token,
    }
    if description is not None:
        input_["description"] = description
    if os_version is not None:
        input_["os_version"] = os_version
    if logging_configuration is not None:
        input_["logging_configuration"] = logging_configuration
    if tags is not None:
        input_["tags"] = tags

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