Skip to content

create_distribution_configuration

create_distribution_configuration(
    name: ResourceName,
    distributions: DistributionList,
    client_token: ClientToken,
    *,
    config_overrides: Optional[imagebuilderClientConfig] = None,
    description: Optional[NonEmptyString] = None,
    tags: Optional[TagMap] = None,
    dry_run: Optional[Boolean] = None,
) -> CreateDistributionConfigurationResponse

Creates a new distribution configuration. Distribution configurations define and configure the outputs for your images, including the target Regions, accounts, and settings for each Region.

Parameters:

  • name (ResourceName) –

    The name of the distribution configuration. Distribution configuration names must be unique to your account in each Amazon Web Services Region. Image Builder generates the distribution configuration 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 distribution configuration.

  • distributions (DistributionList) –

    The distribution settings for the configuration. Each entry defines how output images are distributed in one target Amazon Web Services Region. A Region can appear at most once in the list.

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

    The tags of 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.

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

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

  • DryRunOperationException –

    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.

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

  • InvalidParameterCombinationException –

    You have specified a combination of parameters that isn't valid. For example, two mutually exclusive parameters, or a parameter without its required companion parameter. Review the error message for details.

  • InvalidRequestException –

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

  • ResourceAlreadyExistsException –

    The resource that you are trying to create already exists.

  • 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 a distribution configuration The following example creates a distribution configuration that distributes the output AMI to two Regions. The AMI name includes the build date, so that repeated builds create unique AMI names.

>>> client.create_distribution_configuration(name='my-example-distribution', description='Copies the output AMI to a second Region', distributions=[{'region': 'us-west-2', 'amiDistributionConfiguration': {'name': 'my-example-image-{{ imagebuilder:buildDate }}'}}, {'region': 'us-east-1', 'amiDistributionConfiguration': {'name': 'my-example-image-{{ imagebuilder:buildDate }}'}}], client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLE44444')
Create a distribution configuration with launch permissions and a launch template update
The following example creates a distribution configuration that distributes the output AMI to two Regions. In us-east-1, it shares the AMI with another AWS account. In us-west-2, it sets the new AMI as the default version of your launch template.
>>> client.create_distribution_configuration(name='my-example-distribution', description='Distributes the output AMI to two Regions and shares it with another account', distributions=[{'region': 'us-west-2', 'amiDistributionConfiguration': {'name': 'my-example-image-{{ imagebuilder:buildDate }}'}, 'launchTemplateConfigurations': [{'launchTemplateId': 'lt-1234567890abcdef0', 'setDefaultVersion': True}]}, {'region': 'us-east-1', 'amiDistributionConfiguration': {'name': 'my-example-image-{{ imagebuilder:buildDate }}', 'launchPermission': {'userIds': ['444455556666']}}}], client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLE56789')
Source code in docs_src/capo_imagebuilder/_services/imagebuilder.py
def create_distribution_configuration(
    self,
    name: "capo_imagebuilder.types.resource_name.ResourceName",
    distributions: "capo_imagebuilder.types.distribution_list.DistributionList",
    client_token: "capo_imagebuilder.types.client_token.ClientToken",
    *,
    config_overrides: Optional[imagebuilderClientConfig] = None,
    description: Optional[
        "capo_imagebuilder.types.non_empty_string.NonEmptyString"
    ] = None,
    tags: Optional["capo_imagebuilder.types.tag_map.TagMap"] = None,
    dry_run: Optional["capo_imagebuilder.types.boolean.Boolean"] = None,
) -> "capo_imagebuilder.types.create_distribution_configuration_response.CreateDistributionConfigurationResponse":
    """<p>Creates a new distribution configuration. Distribution configurations define and configure the outputs for your images, including the target Regions, accounts, and settings for each Region.</p>

    Args:
        name: <p>The name of the distribution configuration. Distribution configuration names must be unique to your account in each Amazon Web Services Region. Image Builder generates the distribution configuration 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 distribution configuration.</p>
        distributions: <p>The distribution settings for the configuration. Each entry defines how output images are distributed in one target Amazon Web Services Region. A Region can appear at most once in the list.</p>
        tags: <p>The tags of 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>
        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_parameter_combination_exception.InvalidParameterCombinationException: <p>You have specified a combination of parameters that isn't valid. For example, two mutually exclusive parameters, or a parameter without its required companion parameter. Review the error message for details.</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_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 distribution configuration
        The following example creates a distribution configuration that distributes the output AMI to two Regions. The AMI name includes the build date, so that repeated builds create unique AMI names.

        >>> client.create_distribution_configuration(name='my-example-distribution', description='Copies the output AMI to a second Region', distributions=[{'region': 'us-west-2', 'amiDistributionConfiguration': {'name': 'my-example-image-{{ imagebuilder:buildDate }}'}}, {'region': 'us-east-1', 'amiDistributionConfiguration': {'name': 'my-example-image-{{ imagebuilder:buildDate }}'}}], client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLE44444')
        Create a distribution configuration with launch permissions and a launch template update
        The following example creates a distribution configuration that distributes the output AMI to two Regions. In us-east-1, it shares the AMI with another AWS account. In us-west-2, it sets the new AMI as the default version of your launch template.

        >>> client.create_distribution_configuration(name='my-example-distribution', description='Distributes the output AMI to two Regions and shares it with another account', distributions=[{'region': 'us-west-2', 'amiDistributionConfiguration': {'name': 'my-example-image-{{ imagebuilder:buildDate }}'}, 'launchTemplateConfigurations': [{'launchTemplateId': 'lt-1234567890abcdef0', 'setDefaultVersion': True}]}, {'region': 'us-east-1', 'amiDistributionConfiguration': {'name': 'my-example-image-{{ imagebuilder:buildDate }}', 'launchPermission': {'userIds': ['444455556666']}}}], client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLE56789')
    """

    def _handler(
        req: "OperationRequest[capo_imagebuilder.types.create_distribution_configuration_request.CreateDistributionConfigurationRequest]",
    ) -> OperationResponse[
        "capo_imagebuilder.types.create_distribution_configuration_response.CreateDistributionConfigurationResponse"
    ]:
        import capo_imagebuilder._operations.imagebuilder.create_distribution_configuration

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateDistributionConfiguration")
    )
    input_: capo_imagebuilder.types.create_distribution_configuration_request.CreateDistributionConfigurationRequest = {
        "name": name,
        "distributions": distributions,
        "client_token": client_token,
    }
    if description is not None:
        input_["description"] = description
    if tags is not None:
        input_["tags"] = tags
    if dry_run is not None:
        input_["dry_run"] = dry_run

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