Skip to content

create_container_recipe async

create_container_recipe(
    container_type: ContainerType,
    name: ResourceName,
    semantic_version: WildcardVersionNumber,
    parent_image: NonEmptyString,
    target_repository: TargetContainerRepository,
    client_token: ClientToken,
    *,
    config_overrides: Optional[AsyncimagebuilderClientConfig] = None,
    description: Optional[NonEmptyString] = None,
    components: Optional[ComponentConfigurationList] = None,
    instance_configuration: Optional[InstanceConfiguration] = None,
    dockerfile_template_data: Optional[InlineDockerFileTemplate] = None,
    dockerfile_template_uri: Optional[Uri] = None,
    platform_override: Optional[Platform] = None,
    image_os_version_override: Optional[NonEmptyString] = None,
    tags: Optional[TagMap] = None,
    working_directory: Optional[NonEmptyString] = None,
    kms_key_id: Optional[NonEmptyString] = None,
    dry_run: Optional[Boolean] = None,
) -> CreateContainerRecipeResponse

Creates a new container recipe. Container recipes define how images are configured, tested, and assessed.

Parameters:

  • container_type (ContainerType) –

    The type of container to create.

  • name (ResourceName) –

    The name of the container recipe. The recipe name, combined with the semantic version, must be unique to your account in each Amazon Web Services Region. Image Builder generates the container recipe ARN from a normalized form of the name, so names that differ only in case, spaces, or underscores count as the same name.

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

    The description of the container recipe.

  • semantic_version (WildcardVersionNumber) –

    The semantic version of the container recipe. 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.

  • components (Optional[ComponentConfigurationList], default: None ) –

    The components included in the container recipe. You can specify each component only one time in a recipe.

  • instance_configuration (Optional[InstanceConfiguration], default: None ) –

    A group of options that can be used to configure an instance for building and testing container images.

  • dockerfile_template_data (Optional[InlineDockerFileTemplate], default: None ) –

    The Dockerfile template used to build your image, as an inline data blob. You must specify exactly one of the dockerfileTemplateData or dockerfileTemplateUri properties. For the contextual variables that the template can include, see Create a new version of a container recipe in the EC2 Image Builder User Guide.

  • dockerfile_template_uri (Optional[Uri], default: None ) –

    The Amazon S3 URI for the Dockerfile template that is used to build your container image. You must have permission to read the object. Image Builder reads the object once, when it creates the recipe, and stores its content in the recipe. Later changes to the S3 object don't affect the recipe. You must specify exactly one of the dockerfileTemplateData or dockerfileTemplateUri properties.

  • platform_override (Optional[Platform], default: None ) –

    Specifies the operating system platform when you use a custom base image. Container recipes support only the Linux and Windows platforms.

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

    Specifies the operating system version for the base image. Use this property only when the base image is a container image from a registry. When the base image is an Image Builder image, the operating system version comes from the parent image.

  • parent_image (NonEmptyString) –

    The base image for the container recipe. This can be an Image Builder image resource ARN or a container image URI from a registry, for example amazonlinux:latest.

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

    Tags that are attached to the container recipe.

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

    The working directory for use during build and test workflows.

  • target_repository (TargetContainerRepository) –

    The destination repository for the container image. The Amazon ECR repository must already exist in the Amazon Web Services Region where the build runs.

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

    The Amazon Resource Name (ARN) that uniquely identifies which KMS key is used to encrypt the Dockerfile template. This can be either the Key ARN or the Alias ARN. For more information, see Key identifiers (KeyId) in the Key Management Service Developer Guide.

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

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

    Validates the required permissions and request parameters without performing the operation. If validation succeeds, the operation returns a DryRunOperationException error response.

Raises:

Examples:

Create a container recipe with a custom build instance configuration The following example creates a container recipe that customizes the Amazon EC2 instance that builds the container image. The build instance launches from an Amazon ECS-optimized instance image and uses a 40 GiB gp3 volume.

>>> await client.create_container_recipe(container_type='DOCKER', name='my-example-container-recipe', semantic_version='1.1.0', description='A container recipe that builds on an ECS-optimized instance image with a larger build volume', parent_image='amazonlinux:latest', components=[{'componentArn': 'arn:aws:imagebuilder:us-west-2:111122223333:component/my-example-container-component/1.0.0/1'}], instance_configuration={'image': 'ami-1234567890abcdef0', 'blockDeviceMappings': [{'deviceName': '/dev/xvda', 'ebs': {'volumeSize': 40, 'volumeType': 'gp3', 'deleteOnTermination': True}}]}, dockerfile_template_data='FROM {{{ imagebuilder:parentImage }}}\n{{{ imagebuilder:environments }}}\n{{{ imagebuilder:components }}}\n', target_repository={'service': 'ECR', 'repositoryName': 'my-example-container-repo'}, client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLE40404')
Create a container recipe with an inline Dockerfile template
The following example creates a Docker container recipe that applies one build component, using the latest Amazon Linux container image as the parent and an existing ECR repository as the target.
>>> await client.create_container_recipe(container_type='DOCKER', name='my-example-container-recipe', semantic_version='1.0.0', parent_image='amazonlinux:latest', components=[{'componentArn': 'arn:aws:imagebuilder:us-west-2:111122223333:component/my-example-container-component/1.0.0/1'}], dockerfile_template_data='FROM {{{ imagebuilder:parentImage }}}\n{{{ imagebuilder:environments }}}\n{{{ imagebuilder:components }}}\n', target_repository={'service': 'ECR', 'repositoryName': 'my-example-container-repo'}, client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLE99999')
Source code in docs_src/capo_imagebuilder/_services/async_imagebuilder.py
async def create_container_recipe(
    self,
    container_type: "capo_imagebuilder.types.container_type.ContainerType",
    name: "capo_imagebuilder.types.resource_name.ResourceName",
    semantic_version: "capo_imagebuilder.types.wildcard_version_number.WildcardVersionNumber",
    parent_image: "capo_imagebuilder.types.non_empty_string.NonEmptyString",
    target_repository: "capo_imagebuilder.types.target_container_repository.TargetContainerRepository",
    client_token: "capo_imagebuilder.types.client_token.ClientToken",
    *,
    config_overrides: Optional[AsyncimagebuilderClientConfig] = None,
    description: Optional[
        "capo_imagebuilder.types.non_empty_string.NonEmptyString"
    ] = None,
    components: Optional[
        "capo_imagebuilder.types.component_configuration_list.ComponentConfigurationList"
    ] = None,
    instance_configuration: Optional[
        "capo_imagebuilder.types.instance_configuration.InstanceConfiguration"
    ] = None,
    dockerfile_template_data: Optional[
        "capo_imagebuilder.types.inline_docker_file_template.InlineDockerFileTemplate"
    ] = None,
    dockerfile_template_uri: Optional["capo_imagebuilder.types.uri.Uri"] = None,
    platform_override: Optional["capo_imagebuilder.types.platform.Platform"] = None,
    image_os_version_override: Optional[
        "capo_imagebuilder.types.non_empty_string.NonEmptyString"
    ] = None,
    tags: Optional["capo_imagebuilder.types.tag_map.TagMap"] = None,
    working_directory: Optional[
        "capo_imagebuilder.types.non_empty_string.NonEmptyString"
    ] = None,
    kms_key_id: Optional[
        "capo_imagebuilder.types.non_empty_string.NonEmptyString"
    ] = None,
    dry_run: Optional["capo_imagebuilder.types.boolean.Boolean"] = None,
) -> "capo_imagebuilder.types.create_container_recipe_response.CreateContainerRecipeResponse":
    r"""<p>Creates a new container recipe. Container recipes define how images are configured, tested, and assessed.</p>

    Args:
        container_type: <p>The type of container to create.</p>
        name: <p>The name of the container recipe. The recipe name, combined with the semantic version, must be unique to your account in each Amazon Web Services Region. Image Builder generates the container recipe ARN from a normalized form of the name, so names that differ only in case, spaces, or underscores count as the same name.</p>
        description: <p>The description of the container recipe.</p>
        semantic_version: <p>The semantic version of the container recipe. 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>
        components: <p>The components included in the container recipe. You can specify each component only one time in a recipe.</p>
        instance_configuration: <p>A group of options that can be used to configure an instance for building and testing container images.</p>
        dockerfile_template_data: <p>The Dockerfile template used to build your image, as an inline data blob. You must specify exactly one of the <code>dockerfileTemplateData</code> or <code>dockerfileTemplateUri</code> properties. For the contextual variables that the template can include, see <a href="https://docs.aws.amazon.com/imagebuilder/latest/userguide/create-container-recipes.html">Create a new version of a container recipe</a> in the <i>EC2 Image Builder User Guide</i>.</p>
        dockerfile_template_uri: <p>The Amazon S3 URI for the Dockerfile template that is used to build your container image. You must have permission to read the object. Image Builder reads the object once, when it creates the recipe, and stores its content in the recipe. Later changes to the S3 object don't affect the recipe. You must specify exactly one of the <code>dockerfileTemplateData</code> or <code>dockerfileTemplateUri</code> properties.</p>
        platform_override: <p>Specifies the operating system platform when you use a custom base image. Container recipes support only the Linux and Windows platforms.</p>
        image_os_version_override: <p>Specifies the operating system version for the base image. Use this property only when the base image is a container image from a registry. When the base image is an Image Builder image, the operating system version comes from the parent image.</p>
        parent_image: <p>The base image for the container recipe. This can be an Image Builder image resource ARN or a container image URI from a registry, for example <code>amazonlinux:latest</code>.</p>
        tags: <p>Tags that are attached to the container recipe.</p>
        working_directory: <p>The working directory for use during build and test workflows.</p>
        target_repository: <p>The destination repository for the container image. The Amazon ECR repository must already exist in the Amazon Web Services Region where the build runs.</p>
        kms_key_id: <p>The Amazon Resource Name (ARN) that uniquely identifies which KMS key is used to encrypt the Dockerfile template. This can be either the Key ARN or the Alias ARN. For more information, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id-key-ARN">Key identifiers (KeyId)</a> in the <i>Key Management Service Developer Guide</i>.</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>
        dry_run: <p>Validates the required permissions and request parameters without performing the operation. If validation succeeds, the operation returns a <code>DryRunOperationException</code> error response.</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.dry_run_operation_exception.DryRunOperationException: <p>The dry run operation of the resource was successful, and no resources or mutations were actually performed due to the dry run flag in the request.</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.invalid_version_number_exception.InvalidVersionNumberException: <p>Your version number is out of bounds or does not follow the required syntax.</p>
        capo_imagebuilder.errors.resource_already_exists_exception.ResourceAlreadyExistsException: <p>The resource that you are trying to create already exists.</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 a container recipe with a custom build instance configuration
        The following example creates a container recipe that customizes the Amazon EC2 instance that builds the container image. The build instance launches from an Amazon ECS-optimized instance image and uses a 40 GiB gp3 volume.

        >>> await client.create_container_recipe(container_type='DOCKER', name='my-example-container-recipe', semantic_version='1.1.0', description='A container recipe that builds on an ECS-optimized instance image with a larger build volume', parent_image='amazonlinux:latest', components=[{'componentArn': 'arn:aws:imagebuilder:us-west-2:111122223333:component/my-example-container-component/1.0.0/1'}], instance_configuration={'image': 'ami-1234567890abcdef0', 'blockDeviceMappings': [{'deviceName': '/dev/xvda', 'ebs': {'volumeSize': 40, 'volumeType': 'gp3', 'deleteOnTermination': True}}]}, dockerfile_template_data='FROM {{{ imagebuilder:parentImage }}}\n{{{ imagebuilder:environments }}}\n{{{ imagebuilder:components }}}\n', target_repository={'service': 'ECR', 'repositoryName': 'my-example-container-repo'}, client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLE40404')
        Create a container recipe with an inline Dockerfile template
        The following example creates a Docker container recipe that applies one build component, using the latest Amazon Linux container image as the parent and an existing ECR repository as the target.

        >>> await client.create_container_recipe(container_type='DOCKER', name='my-example-container-recipe', semantic_version='1.0.0', parent_image='amazonlinux:latest', components=[{'componentArn': 'arn:aws:imagebuilder:us-west-2:111122223333:component/my-example-container-component/1.0.0/1'}], dockerfile_template_data='FROM {{{ imagebuilder:parentImage }}}\n{{{ imagebuilder:environments }}}\n{{{ imagebuilder:components }}}\n', target_repository={'service': 'ECR', 'repositoryName': 'my-example-container-repo'}, client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLE99999')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_imagebuilder.types.create_container_recipe_request.CreateContainerRecipeRequest]",
    ) -> AsyncOperationResponse[
        "capo_imagebuilder.types.create_container_recipe_response.CreateContainerRecipeResponse"
    ]:
        import capo_imagebuilder._operations.imagebuilder.create_container_recipe

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateContainerRecipe")
    )
    input_: capo_imagebuilder.types.create_container_recipe_request.CreateContainerRecipeRequest = {
        "container_type": container_type,
        "name": name,
        "semantic_version": semantic_version,
        "parent_image": parent_image,
        "target_repository": target_repository,
        "client_token": client_token,
    }
    if description is not None:
        input_["description"] = description
    if components is not None:
        input_["components"] = components
    if instance_configuration is not None:
        input_["instance_configuration"] = instance_configuration
    if dockerfile_template_data is not None:
        input_["dockerfile_template_data"] = dockerfile_template_data
    if dockerfile_template_uri is not None:
        input_["dockerfile_template_uri"] = dockerfile_template_uri
    if platform_override is not None:
        input_["platform_override"] = platform_override
    if image_os_version_override is not None:
        input_["image_os_version_override"] = image_os_version_override
    if tags is not None:
        input_["tags"] = tags
    if working_directory is not None:
        input_["working_directory"] = working_directory
    if kms_key_id is not None:
        input_["kms_key_id"] = kms_key_id
    if dry_run is not None:
        input_["dry_run"] = dry_run

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