Skip to content

create_image async

create_image(
    infrastructure_configuration_arn: InfrastructureConfigurationArn,
    client_token: ClientToken,
    *,
    config_overrides: Optional[AsyncimagebuilderClientConfig] = None,
    image_recipe_arn: Optional[ImageRecipeArn] = None,
    container_recipe_arn: Optional[ContainerRecipeArn] = None,
    distribution_configuration_arn: Optional[DistributionConfigurationArn] = None,
    image_tests_configuration: Optional[ImageTestsConfiguration] = None,
    enhanced_image_metadata_enabled: Optional[NullableBoolean] = None,
    tags: Optional[TagMap] = None,
    image_scanning_configuration: Optional[ImageScanningConfiguration] = None,
    workflows: Optional[WorkflowConfigurationList] = None,
    execution_role: Optional[RoleNameOrArn] = None,
    logging_configuration: Optional[ImageLoggingConfiguration] = None,
) -> CreateImageResponse

Creates a new image along with all configured output resources defined in the distribution configuration. You must specify exactly one recipe for your image, using either a containerRecipeArn or an imageRecipeArn.

The response returns as soon as Image Builder creates the new image resource. The image build process runs asynchronously. To check its progress, call GetImage and check the image status.

Parameters:

  • image_recipe_arn (Optional[ImageRecipeArn], default: None ) –

    The Amazon Resource Name (ARN) of the image recipe that defines how images are configured, tested, and assessed. You must specify either this property or containerRecipeArn, but not both.

  • container_recipe_arn (Optional[ContainerRecipeArn], default: None ) –

    The Amazon Resource Name (ARN) of the container recipe that defines how images are configured and tested. You must specify either this property or imageRecipeArn, but not both.

  • distribution_configuration_arn (Optional[DistributionConfigurationArn], default: None ) –

    The Amazon Resource Name (ARN) of the distribution configuration that defines and configures the outputs of the image build. If you don't specify a distribution configuration, Image Builder creates the output image only in the account and Amazon Web Services Region where the build runs.

  • infrastructure_configuration_arn (InfrastructureConfigurationArn) –

    The Amazon Resource Name (ARN) of the infrastructure configuration that defines the environment in which your image will be built and tested.

  • image_tests_configuration (Optional[ImageTestsConfiguration], default: None ) –

    Settings that determine whether Image Builder runs tests on the image after building it. Image tests are enabled by default.

  • enhanced_image_metadata_enabled (Optional[NullableBoolean], default: None ) –

    Specifies whether to collect additional information about the image being created, including the operating system (OS) version and package list. Defaults to true.

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

    The tags of the image.

  • 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.

  • image_scanning_configuration (Optional[ImageScanningConfiguration], default: None ) –

    Settings for vulnerability scans that Amazon Inspector runs during image creation. For AMI output, Amazon Inspector scans the test instance. For container output, Amazon Inspector scans the container image that Image Builder pushes to the Amazon ECR repository specified in ecrConfiguration.

  • workflows (Optional[WorkflowConfigurationList], default: None ) –

    The array of workflow configuration objects for the build. If you specify workflows, they replace the default workflows that Image Builder otherwise runs for the build, and you must also provide an executionRole.

  • execution_role (Optional[RoleNameOrArn], default: None ) –

    The name or Amazon Resource Name (ARN) for the IAM role you create that grants Image Builder access to perform workflow actions. This property is required if you specify workflows. If you don't provide a role, Image Builder uses the Image Builder service-linked role in your account, and creates it if it doesn't exist.

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

    The CloudWatch Logs log group where Image Builder sends the image build logs. If you specify a log group name outside of the /aws/imagebuilder/ namespace, you must also provide an executionRole that has permission to write to that log group.

Raises:

  • CallRateLimitExceededException –

    You have exceeded the permitted request rate for the Amazon EC2 APIs that Image Builder calls on your behalf. Retry with an increasing or variable delay between requests.

  • 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.

  • ForbiddenException –

    You are not authorized to perform the requested operation.

  • IdempotentParameterMismatchException –

    You have specified a client token for an operation using parameter values that differ from a previous request that used the same client token.

  • InvalidRequestException –

    The request is malformed or otherwise invalid. Verify the request and try again.

  • ResourceInUseException –

    The resource that you are trying to operate on is currently in use. Review the message details and retry later.

  • ServiceException –

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

  • ServiceQuotaExceededException –

    You have exceeded the number of permitted resources or operations for this service. For service quotas, see EC2 Image Builder endpoints and quotas.

  • 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:

Create an image The following example creates a new image from the specified image recipe and infrastructure configuration.

>>> await client.create_image(image_recipe_arn='arn:aws:imagebuilder:us-west-2:111122223333:image-recipe/my-example-recipe/1.0.0', infrastructure_configuration_arn='arn:aws:imagebuilder:us-west-2:111122223333:infrastructure-configuration/my-example-infrastructure', client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLEeeeee')
Create an image with custom build and parallel test workflows
The following example creates an image that uses your custom build and test workflows. It uses the Image Builder service-linked role as the execution role. Both test workflows are in the same parallel group, so they can run at the same time after the build workflow completes.
>>> await client.create_image(image_recipe_arn='arn:aws:imagebuilder:us-west-2:111122223333:image-recipe/my-example-recipe/1.0.0', infrastructure_configuration_arn='arn:aws:imagebuilder:us-west-2:111122223333:infrastructure-configuration/my-example-infrastructure', workflows=[{'workflowArn': 'arn:aws:imagebuilder:us-west-2:111122223333:workflow/build/my-example-workflow/1.0.0/1'}, {'workflowArn': 'arn:aws:imagebuilder:us-west-2:111122223333:workflow/test/my-example-integration-tests/1.0.0/1', 'parallelGroup': 'post-build-tests'}, {'workflowArn': 'arn:aws:imagebuilder:us-west-2:111122223333:workflow/test/my-example-compliance-tests/1.0.0/1', 'parallelGroup': 'post-build-tests'}], execution_role='arn:aws:iam::111122223333:role/aws-service-role/imagebuilder.amazonaws.com/AWSServiceRoleForImageBuilder', client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLE01234')
Source code in docs_src/capo_imagebuilder/_services/async_imagebuilder.py
async def create_image(
    self,
    infrastructure_configuration_arn: "capo_imagebuilder.types.infrastructure_configuration_arn.InfrastructureConfigurationArn",
    client_token: "capo_imagebuilder.types.client_token.ClientToken",
    *,
    config_overrides: Optional[AsyncimagebuilderClientConfig] = None,
    image_recipe_arn: Optional[
        "capo_imagebuilder.types.image_recipe_arn.ImageRecipeArn"
    ] = None,
    container_recipe_arn: Optional[
        "capo_imagebuilder.types.container_recipe_arn.ContainerRecipeArn"
    ] = None,
    distribution_configuration_arn: Optional[
        "capo_imagebuilder.types.distribution_configuration_arn.DistributionConfigurationArn"
    ] = None,
    image_tests_configuration: Optional[
        "capo_imagebuilder.types.image_tests_configuration.ImageTestsConfiguration"
    ] = None,
    enhanced_image_metadata_enabled: Optional[
        "capo_imagebuilder.types.nullable_boolean.NullableBoolean"
    ] = None,
    tags: Optional["capo_imagebuilder.types.tag_map.TagMap"] = None,
    image_scanning_configuration: Optional[
        "capo_imagebuilder.types.image_scanning_configuration.ImageScanningConfiguration"
    ] = None,
    workflows: Optional[
        "capo_imagebuilder.types.workflow_configuration_list.WorkflowConfigurationList"
    ] = None,
    execution_role: Optional[
        "capo_imagebuilder.types.role_name_or_arn.RoleNameOrArn"
    ] = None,
    logging_configuration: Optional[
        "capo_imagebuilder.types.image_logging_configuration.ImageLoggingConfiguration"
    ] = None,
) -> "capo_imagebuilder.types.create_image_response.CreateImageResponse":
    """<p>Creates a new image along with all configured output resources defined in the distribution configuration. You must specify exactly one recipe for your image, using either a <code>containerRecipeArn</code> or an <code>imageRecipeArn</code>.</p> <p>The response returns as soon as Image Builder creates the new image resource. The image build process runs asynchronously. To check its progress, call <a href="https://docs.aws.amazon.com/imagebuilder/latest/APIReference/API_GetImage.html">GetImage</a> and check the image status.</p>

    Args:
        image_recipe_arn: <p>The Amazon Resource Name (ARN) of the image recipe that defines how images are configured, tested, and assessed. You must specify either this property or <code>containerRecipeArn</code>, but not both.</p>
        container_recipe_arn: <p>The Amazon Resource Name (ARN) of the container recipe that defines how images are configured and tested. You must specify either this property or <code>imageRecipeArn</code>, but not both.</p>
        distribution_configuration_arn: <p>The Amazon Resource Name (ARN) of the distribution configuration that defines and configures the outputs of the image build. If you don't specify a distribution configuration, Image Builder creates the output image only in the account and Amazon Web Services Region where the build runs.</p>
        infrastructure_configuration_arn: <p>The Amazon Resource Name (ARN) of the infrastructure configuration that defines the environment in which your image will be built and tested.</p>
        image_tests_configuration: <p>Settings that determine whether Image Builder runs tests on the image after building it. Image tests are enabled by default.</p>
        enhanced_image_metadata_enabled: <p>Specifies whether to collect additional information about the image being created, including the operating system (OS) version and package list. Defaults to <code>true</code>.</p>
        tags: <p>The tags of the image.</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>
        image_scanning_configuration: <p>Settings for vulnerability scans that Amazon Inspector runs during image creation. For AMI output, Amazon Inspector scans the test instance. For container output, Amazon Inspector scans the container image that Image Builder pushes to the Amazon ECR repository specified in <code>ecrConfiguration</code>.</p>
        workflows: <p>The array of workflow configuration objects for the build. If you specify workflows, they replace the default workflows that Image Builder otherwise runs for the build, and you must also provide an <code>executionRole</code>.</p>
        execution_role: <p>The name or Amazon Resource Name (ARN) for the IAM role you create that grants Image Builder access to perform workflow actions. This property is required if you specify <code>workflows</code>. If you don't provide a role, Image Builder uses the Image Builder service-linked role in your account, and creates it if it doesn't exist.</p>
        logging_configuration: <p>The CloudWatch Logs log group where Image Builder sends the image build logs. If you specify a log group name outside of the <code>/aws/imagebuilder/</code> namespace, you must also provide an <code>executionRole</code> that has permission to write to that log group.</p>

    Raises:
        capo_imagebuilder.errors.call_rate_limit_exceeded_exception.CallRateLimitExceededException: <p>You have exceeded the permitted request rate for the Amazon EC2 APIs that Image Builder calls on your behalf. Retry with an increasing or variable delay between requests.</p>
        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.forbidden_exception.ForbiddenException: <p>You are not authorized to perform the requested operation.</p>
        capo_imagebuilder.errors.idempotent_parameter_mismatch_exception.IdempotentParameterMismatchException: <p>You have specified a client token for an operation using parameter values that differ from a previous request that used the same client token.</p>
        capo_imagebuilder.errors.invalid_request_exception.InvalidRequestException: <p>The request is malformed or otherwise invalid. Verify the request and try again.</p>
        capo_imagebuilder.errors.resource_in_use_exception.ResourceInUseException: <p>The resource that you are trying to operate on is currently in use. Review the message details and retry later.</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_quota_exceeded_exception.ServiceQuotaExceededException: <p>You have exceeded the number of permitted resources or operations for this service. For service quotas, see <a href="https://docs.aws.amazon.com/general/latest/gr/imagebuilder.html#limits_imagebuilder">EC2 Image Builder endpoints and quotas</a>.</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:
        Create an image
        The following example creates a new image from the specified image recipe and infrastructure configuration.

        >>> await client.create_image(image_recipe_arn='arn:aws:imagebuilder:us-west-2:111122223333:image-recipe/my-example-recipe/1.0.0', infrastructure_configuration_arn='arn:aws:imagebuilder:us-west-2:111122223333:infrastructure-configuration/my-example-infrastructure', client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLEeeeee')
        Create an image with custom build and parallel test workflows
        The following example creates an image that uses your custom build and test workflows. It uses the Image Builder service-linked role as the execution role. Both test workflows are in the same parallel group, so they can run at the same time after the build workflow completes.

        >>> await client.create_image(image_recipe_arn='arn:aws:imagebuilder:us-west-2:111122223333:image-recipe/my-example-recipe/1.0.0', infrastructure_configuration_arn='arn:aws:imagebuilder:us-west-2:111122223333:infrastructure-configuration/my-example-infrastructure', workflows=[{'workflowArn': 'arn:aws:imagebuilder:us-west-2:111122223333:workflow/build/my-example-workflow/1.0.0/1'}, {'workflowArn': 'arn:aws:imagebuilder:us-west-2:111122223333:workflow/test/my-example-integration-tests/1.0.0/1', 'parallelGroup': 'post-build-tests'}, {'workflowArn': 'arn:aws:imagebuilder:us-west-2:111122223333:workflow/test/my-example-compliance-tests/1.0.0/1', 'parallelGroup': 'post-build-tests'}], execution_role='arn:aws:iam::111122223333:role/aws-service-role/imagebuilder.amazonaws.com/AWSServiceRoleForImageBuilder', client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLE01234')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_imagebuilder.types.create_image_request.CreateImageRequest]",
    ) -> AsyncOperationResponse[
        "capo_imagebuilder.types.create_image_response.CreateImageResponse"
    ]:
        import capo_imagebuilder._operations.imagebuilder.create_image

        (
            output,
            http_response,
        ) = await capo_imagebuilder._operations.imagebuilder.create_image.async_create_image(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateImage")
    )
    input_: capo_imagebuilder.types.create_image_request.CreateImageRequest = {
        "infrastructure_configuration_arn": infrastructure_configuration_arn,
        "client_token": client_token,
    }
    if image_recipe_arn is not None:
        input_["image_recipe_arn"] = image_recipe_arn
    if container_recipe_arn is not None:
        input_["container_recipe_arn"] = container_recipe_arn
    if distribution_configuration_arn is not None:
        input_["distribution_configuration_arn"] = distribution_configuration_arn
    if image_tests_configuration is not None:
        input_["image_tests_configuration"] = image_tests_configuration
    if enhanced_image_metadata_enabled is not None:
        input_["enhanced_image_metadata_enabled"] = enhanced_image_metadata_enabled
    if tags is not None:
        input_["tags"] = tags
    if image_scanning_configuration is not None:
        input_["image_scanning_configuration"] = image_scanning_configuration
    if workflows is not None:
        input_["workflows"] = workflows
    if execution_role is not None:
        input_["execution_role"] = execution_role
    if logging_configuration is not None:
        input_["logging_configuration"] = logging_configuration

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