Skip to content

distribute_image

distribute_image(
    source_image: NonEmptyString,
    distribution_configuration_arn: DistributionConfigurationArn,
    execution_role: RoleNameOrArn,
    client_token: ClientToken,
    *,
    config_overrides: Optional[imagebuilderClientConfig] = None,
    tags: Optional[TagMap] = None,
    logging_configuration: Optional[ImageLoggingConfiguration] = None,
) -> DistributeImageResponse

Distributes an existing AMI to target Regions and accounts without running the full image build process. This operation only runs the distribution phase on an image that has already been built.

Parameters:

  • source_image (NonEmptyString) –

    The source image to distribute. You can specify the source in any of the following formats:

    • An AMI ID.

    • An Amazon Web Services Systems Manager Parameter Store reference, prefixed by ssm:, followed by the parameter name or ARN.

    • An Image Builder image Amazon Resource Name (ARN). An image version ARN resolves to the latest available build version.

    Whichever format you use, the source must resolve to an AMI in the current Amazon Web Services Region.

  • distribution_configuration_arn (DistributionConfigurationArn) –

    The Amazon Resource Name (ARN) of the distribution configuration. The configuration defines target Regions, accounts, and AMI settings. The distribution configuration must be in the same Region as this operation.

  • execution_role (RoleNameOrArn) –

    The name or Amazon Resource Name (ARN) of the IAM role that Image Builder assumes to distribute the image.

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

    The tags to apply to the new Image Builder image resource that this operation creates. To tag the output AMIs, use amiTags in the distribution configuration.

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

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

    The logging configuration for the distribution.

Raises:

Examples:

Distribute an existing AMI The following example distributes an AMI that you own to the targets defined in the specified distribution configuration. It returns the ARN of a new Image Builder image resource that you can use with GetImage to monitor distribution progress.

>>> client.distribute_image(source_image='ami-1234567890abcdef0', distribution_configuration_arn='arn:aws:imagebuilder:us-west-2:111122223333:distribution-configuration/my-example-distribution-configuration', execution_role='arn:aws:iam::111122223333:role/aws-service-role/imagebuilder.amazonaws.com/AWSServiceRoleForImageBuilder', client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLE86420')
Source code in docs_src/capo_imagebuilder/_services/imagebuilder.py
def distribute_image(
    self,
    source_image: "capo_imagebuilder.types.non_empty_string.NonEmptyString",
    distribution_configuration_arn: "capo_imagebuilder.types.distribution_configuration_arn.DistributionConfigurationArn",
    execution_role: "capo_imagebuilder.types.role_name_or_arn.RoleNameOrArn",
    client_token: "capo_imagebuilder.types.client_token.ClientToken",
    *,
    config_overrides: Optional[imagebuilderClientConfig] = None,
    tags: Optional["capo_imagebuilder.types.tag_map.TagMap"] = None,
    logging_configuration: Optional[
        "capo_imagebuilder.types.image_logging_configuration.ImageLoggingConfiguration"
    ] = None,
) -> "capo_imagebuilder.types.distribute_image_response.DistributeImageResponse":
    """<p>Distributes an existing AMI to target Regions and accounts without running the full image build process. This operation only runs the distribution phase on an image that has already been built.</p>

    Args:
        source_image: <p>The source image to distribute. You can specify the source in any of the following formats:</p> <ul> <li> <p>An AMI ID.</p> </li> <li> <p>An Amazon Web Services Systems Manager Parameter Store reference, prefixed by <code>ssm:</code>, followed by the parameter name or ARN.</p> </li> <li> <p>An Image Builder image Amazon Resource Name (ARN). An image version ARN resolves to the latest available build version.</p> </li> </ul> <p>Whichever format you use, the source must resolve to an AMI in the current Amazon Web Services Region.</p>
        distribution_configuration_arn: <p>The Amazon Resource Name (ARN) of the distribution configuration. The configuration defines target Regions, accounts, and AMI settings. The distribution configuration must be in the same Region as this operation.</p>
        execution_role: <p>The name or Amazon Resource Name (ARN) of the IAM role that Image Builder assumes to distribute the image.</p>
        tags: <p>The tags to apply to the new Image Builder image resource that this operation creates. To tag the output AMIs, use <code>amiTags</code> in the distribution configuration.</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>
        logging_configuration: <p>The logging configuration for the distribution.</p>

    Raises:
        capo_imagebuilder.errors.access_denied_exception.AccessDeniedException: <p>You do not have permissions to perform the requested operation.</p>
        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.resource_not_found_exception.ResourceNotFoundException: <p>At least one of the resources referenced by your request does not exist.</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.too_many_requests_exception.TooManyRequestsException: <p>You have attempted too many requests for the specific operation.</p>
        capo_imagebuilder.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        Distribute an existing AMI
        The following example distributes an AMI that you own to the targets defined in the specified distribution configuration. It returns the ARN of a new Image Builder image resource that you can use with GetImage to monitor distribution progress.

        >>> client.distribute_image(source_image='ami-1234567890abcdef0', distribution_configuration_arn='arn:aws:imagebuilder:us-west-2:111122223333:distribution-configuration/my-example-distribution-configuration', execution_role='arn:aws:iam::111122223333:role/aws-service-role/imagebuilder.amazonaws.com/AWSServiceRoleForImageBuilder', client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLE86420')
    """

    def _handler(
        req: "OperationRequest[capo_imagebuilder.types.distribute_image_request.DistributeImageRequest]",
    ) -> OperationResponse[
        "capo_imagebuilder.types.distribute_image_response.DistributeImageResponse"
    ]:
        import capo_imagebuilder._operations.imagebuilder.distribute_image

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("DistributeImage")
    )
    input_: capo_imagebuilder.types.distribute_image_request.DistributeImageRequest = {
        "source_image": source_image,
        "distribution_configuration_arn": distribution_configuration_arn,
        "execution_role": execution_role,
        "client_token": client_token,
    }
    if tags is not None:
        input_["tags"] = tags
    if logging_configuration is not None:
        input_["logging_configuration"] = logging_configuration

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