Skip to content

update_distribution

update_distribution(
    distribution_config: DistributionConfig,
    id: string,
    *,
    config_overrides: Optional[CloudFrontClientConfig] = None,
    if_match: Optional[string] = None,
) -> UpdateDistributionResult

Updates the configuration for a CloudFront distribution.

The update process includes getting the current distribution configuration, updating it to make your changes, and then submitting an UpdateDistribution request to make the updates.

To update a web distribution using the CloudFront API

  1. Use GetDistributionConfig to get the current configuration, including the version identifier (ETag).

  2. Update the distribution configuration that was returned in the response. Note the following important requirements and restrictions:

    • You must copy the ETag field value from the response. (You'll use it for the IfMatch parameter in your request.) Then, remove the ETag field from the distribution configuration.

    • You can't change the value of CallerReference.

  3. Submit an UpdateDistribution request, providing the updated distribution configuration. The new configuration replaces the existing configuration. The values that you specify in an UpdateDistribution request are not merged into your existing configuration. Make sure to include all fields: the ones that you modified and also the ones that you didn't.

Parameters:

  • distribution_config (DistributionConfig) –

    The distribution's configuration information.

  • id (string) –

    The distribution's id.

  • if_match (Optional[string], default: None ) –

    The value of the ETag header that you received when retrieving the distribution's configuration. For example: E2QWRUHAPOMQZL.

Raises:

Source code in docs_src/capo_cloudfront/_services/cloud_front.py
def update_distribution(
    self,
    distribution_config: "capo_cloudfront.types.distribution_config.DistributionConfig",
    id: "capo_cloudfront.types.string.string",
    *,
    config_overrides: Optional[CloudFrontClientConfig] = None,
    if_match: Optional["capo_cloudfront.types.string.string"] = None,
) -> "capo_cloudfront.types.update_distribution_result.UpdateDistributionResult":
    """<p>Updates the configuration for a CloudFront distribution.</p> <p>The update process includes getting the current distribution configuration, updating it to make your changes, and then submitting an <code>UpdateDistribution</code> request to make the updates.</p> <p> <b>To update a web distribution using the CloudFront API</b> </p> <ol> <li> <p>Use <code>GetDistributionConfig</code> to get the current configuration, including the version identifier (<code>ETag</code>).</p> </li> <li> <p>Update the distribution configuration that was returned in the response. Note the following important requirements and restrictions:</p> <ul> <li> <p>You must copy the <code>ETag</code> field value from the response. (You'll use it for the <code>IfMatch</code> parameter in your request.) Then, remove the <code>ETag</code> field from the distribution configuration.</p> </li> <li> <p>You can't change the value of <code>CallerReference</code>.</p> </li> </ul> </li> <li> <p>Submit an <code>UpdateDistribution</code> request, providing the updated distribution configuration. The new configuration replaces the existing configuration. The values that you specify in an <code>UpdateDistribution</code> request are not merged into your existing configuration. Make sure to include all fields: the ones that you modified and also the ones that you didn't.</p> </li> </ol>

    Args:
        distribution_config: <p>The distribution's configuration information.</p>
        id: <p>The distribution's id.</p>
        if_match: <p>The value of the <code>ETag</code> header that you received when retrieving the distribution's configuration. For example: <code>E2QWRUHAPOMQZL</code>.</p>

    Raises:
        capo_cloudfront.errors.access_denied.AccessDenied: <p>Access denied.</p>
        capo_cloudfront.errors.cname_already_exists.CNAMEAlreadyExists: <p>The CNAME specified is already defined for CloudFront.</p>
        capo_cloudfront.errors.continuous_deployment_policy_in_use.ContinuousDeploymentPolicyInUse: <p>You cannot delete a continuous deployment policy that is associated with a primary distribution.</p>
        capo_cloudfront.errors.entity_not_found.EntityNotFound: <p>The entity was not found.</p>
        capo_cloudfront.errors.illegal_field_level_encryption_config_association_with_cache_behavior.IllegalFieldLevelEncryptionConfigAssociationWithCacheBehavior: <p>The specified configuration for field-level encryption can't be associated with the specified cache behavior.</p>
        capo_cloudfront.errors.illegal_origin_access_configuration.IllegalOriginAccessConfiguration: <p>An origin cannot contain both an origin access control (OAC) and an origin access identity (OAI).</p>
        capo_cloudfront.errors.illegal_update.IllegalUpdate: <p>The update contains modifications that are not allowed.</p>
        capo_cloudfront.errors.inconsistent_quantities.InconsistentQuantities: <p>The value of <code>Quantity</code> and the size of <code>Items</code> don't match.</p>
        capo_cloudfront.errors.invalid_argument.InvalidArgument: <p>An argument is invalid.</p>
        capo_cloudfront.errors.invalid_default_root_object.InvalidDefaultRootObject: <p>The default root object file name is too big or contains an invalid character.</p>
        capo_cloudfront.errors.invalid_domain_name_for_origin_access_control.InvalidDomainNameForOriginAccessControl: <p>An origin access control is associated with an origin whose domain name is not supported.</p>
        capo_cloudfront.errors.invalid_error_code.InvalidErrorCode: <p>An invalid error code was specified.</p>
        capo_cloudfront.errors.invalid_forward_cookies.InvalidForwardCookies: <p>Your request contains forward cookies option which doesn't match with the expectation for the <code>whitelisted</code> list of cookie names. Either list of cookie names has been specified when not allowed or list of cookie names is missing when expected.</p>
        capo_cloudfront.errors.invalid_function_association.InvalidFunctionAssociation: <p>A CloudFront function association is invalid.</p>
        capo_cloudfront.errors.invalid_geo_restriction_parameter.InvalidGeoRestrictionParameter: <p>The specified geo restriction parameter is not valid.</p>
        capo_cloudfront.errors.invalid_headers_for_s3_origin.InvalidHeadersForS3Origin: <p>The headers specified are not valid for an Amazon S3 origin.</p>
        capo_cloudfront.errors.invalid_if_match_version.InvalidIfMatchVersion: <p>The <code>If-Match</code> version is missing or not valid.</p>
        capo_cloudfront.errors.invalid_lambda_function_association.InvalidLambdaFunctionAssociation: <p>The specified Lambda@Edge function association is invalid.</p>
        capo_cloudfront.errors.invalid_location_code.InvalidLocationCode: <p>The location code specified is not valid.</p>
        capo_cloudfront.errors.invalid_minimum_protocol_version.InvalidMinimumProtocolVersion: <p>The minimum protocol version specified is not valid.</p>
        capo_cloudfront.errors.invalid_origin_access_control.InvalidOriginAccessControl: <p>The origin access control is not valid.</p>
        capo_cloudfront.errors.invalid_origin_access_identity.InvalidOriginAccessIdentity: <p>The origin access identity is not valid or doesn't exist.</p>
        capo_cloudfront.errors.invalid_origin_keepalive_timeout.InvalidOriginKeepaliveTimeout: <p>The keep alive timeout specified for the origin is not valid.</p>
        capo_cloudfront.errors.invalid_origin_read_timeout.InvalidOriginReadTimeout: <p>The read timeout specified for the origin is not valid.</p>
        capo_cloudfront.errors.invalid_query_string_parameters.InvalidQueryStringParameters: <p>The query string parameters specified are not valid.</p>
        capo_cloudfront.errors.invalid_relative_path.InvalidRelativePath: <p>The relative path is too big, is not URL-encoded, or does not begin with a slash (/).</p>
        capo_cloudfront.errors.invalid_required_protocol.InvalidRequiredProtocol: <p>This operation requires the HTTPS protocol. Ensure that you specify the HTTPS protocol in your request, or omit the <code>RequiredProtocols</code> element from your distribution configuration.</p>
        capo_cloudfront.errors.invalid_response_code.InvalidResponseCode: <p>A response code is not valid.</p>
        capo_cloudfront.errors.invalid_ttl_order.InvalidTTLOrder: <p>The TTL order specified is not valid.</p>
        capo_cloudfront.errors.invalid_viewer_certificate.InvalidViewerCertificate: <p>A viewer certificate specified is not valid.</p>
        capo_cloudfront.errors.invalid_web_acl_id.InvalidWebACLId: <p>A web ACL ID specified is not valid. To specify a web ACL created using the latest version of WAF, use the ACL ARN, for example <code>arn:aws:wafv2:us-east-1:123456789012:global/webacl/ExampleWebACL/473e64fd-f30b-4765-81a0-62ad96dd167a</code>. To specify a web ACL created using WAF Classic, use the ACL ID, for example <code>473e64fd-f30b-4765-81a0-62ad96dd167a</code>.</p>
        capo_cloudfront.errors.missing_body.MissingBody: <p>This operation requires a body. Ensure that the body is present and the <code>Content-Type</code> header is set.</p>
        capo_cloudfront.errors.no_such_cache_policy.NoSuchCachePolicy: <p>The cache policy does not exist.</p>
        capo_cloudfront.errors.no_such_continuous_deployment_policy.NoSuchContinuousDeploymentPolicy: <p>The continuous deployment policy doesn't exist.</p>
        capo_cloudfront.errors.no_such_distribution.NoSuchDistribution: <p>The specified distribution does not exist.</p>
        capo_cloudfront.errors.no_such_field_level_encryption_config.NoSuchFieldLevelEncryptionConfig: <p>The specified configuration for field-level encryption doesn't exist.</p>
        capo_cloudfront.errors.no_such_origin.NoSuchOrigin: <p>No origin exists with the specified <code>Origin Id</code>.</p>
        capo_cloudfront.errors.no_such_origin_request_policy.NoSuchOriginRequestPolicy: <p>The origin request policy does not exist.</p>
        capo_cloudfront.errors.no_such_realtime_log_config.NoSuchRealtimeLogConfig: <p>The real-time log configuration does not exist.</p>
        capo_cloudfront.errors.no_such_response_headers_policy.NoSuchResponseHeadersPolicy: <p>The response headers policy does not exist.</p>
        capo_cloudfront.errors.precondition_failed.PreconditionFailed: <p>The precondition in one or more of the request fields evaluated to <code>false</code>.</p>
        capo_cloudfront.errors.realtime_log_config_owner_mismatch.RealtimeLogConfigOwnerMismatch: <p>The specified real-time log configuration belongs to a different Amazon Web Services account.</p>
        capo_cloudfront.errors.staging_distribution_in_use.StagingDistributionInUse: <p>A continuous deployment policy for this staging distribution already exists.</p>
        capo_cloudfront.errors.too_many_cache_behaviors.TooManyCacheBehaviors: <p>You cannot create more cache behaviors for the distribution.</p>
        capo_cloudfront.errors.too_many_certificates.TooManyCertificates: <p>You cannot create anymore custom SSL/TLS certificates.</p>
        capo_cloudfront.errors.too_many_cookie_names_in_white_list.TooManyCookieNamesInWhiteList: <p>Your request contains more cookie names in the whitelist than are allowed per cache behavior.</p>
        capo_cloudfront.errors.too_many_distribution_cnam_es.TooManyDistributionCNAMEs: <p>Your request contains more CNAMEs than are allowed per distribution.</p>
        capo_cloudfront.errors.too_many_distributions_associated_to_cache_policy.TooManyDistributionsAssociatedToCachePolicy: <p>The maximum number of distributions have been associated with the specified cache policy. For more information, see <a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html">Quotas</a> (formerly known as limits) in the <i>Amazon CloudFront Developer Guide</i>.</p>
        capo_cloudfront.errors.too_many_distributions_associated_to_field_level_encryption_config.TooManyDistributionsAssociatedToFieldLevelEncryptionConfig: <p>The maximum number of distributions have been associated with the specified configuration for field-level encryption.</p>
        capo_cloudfront.errors.too_many_distributions_associated_to_key_group.TooManyDistributionsAssociatedToKeyGroup: <p>The number of distributions that reference this key group is more than the maximum allowed. For more information, see <a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html">Quotas</a> (formerly known as limits) in the <i>Amazon CloudFront Developer Guide</i>.</p>
        capo_cloudfront.errors.too_many_distributions_associated_to_origin_access_control.TooManyDistributionsAssociatedToOriginAccessControl: <p>The maximum number of distributions have been associated with the specified origin access control.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html">Quotas</a> (formerly known as limits) in the <i>Amazon CloudFront Developer Guide</i>.</p>
        capo_cloudfront.errors.too_many_distributions_associated_to_origin_request_policy.TooManyDistributionsAssociatedToOriginRequestPolicy: <p>The maximum number of distributions have been associated with the specified origin request policy. For more information, see <a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html">Quotas</a> (formerly known as limits) in the <i>Amazon CloudFront Developer Guide</i>.</p>
        capo_cloudfront.errors.too_many_distributions_associated_to_response_headers_policy.TooManyDistributionsAssociatedToResponseHeadersPolicy: <p>The maximum number of distributions have been associated with the specified response headers policy.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html">Quotas</a> (formerly known as limits) in the <i>Amazon CloudFront Developer Guide</i>.</p>
        capo_cloudfront.errors.too_many_distributions_with_function_associations.TooManyDistributionsWithFunctionAssociations: <p>You have reached the maximum number of distributions that are associated with a CloudFront function. For more information, see <a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html">Quotas</a> (formerly known as limits) in the <i>Amazon CloudFront Developer Guide</i>.</p>
        capo_cloudfront.errors.too_many_distributions_with_lambda_associations.TooManyDistributionsWithLambdaAssociations: <p>Processing your request would cause the maximum number of distributions with Lambda@Edge function associations per owner to be exceeded.</p>
        capo_cloudfront.errors.too_many_distributions_with_single_function_arn.TooManyDistributionsWithSingleFunctionARN: <p>The maximum number of distributions have been associated with the specified Lambda@Edge function.</p>
        capo_cloudfront.errors.too_many_function_associations.TooManyFunctionAssociations: <p>You have reached the maximum number of CloudFront function associations for this distribution. For more information, see <a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html">Quotas</a> (formerly known as limits) in the <i>Amazon CloudFront Developer Guide</i>.</p>
        capo_cloudfront.errors.too_many_headers_in_forwarded_values.TooManyHeadersInForwardedValues: <p>Your request contains too many headers in forwarded values.</p>
        capo_cloudfront.errors.too_many_key_groups_associated_to_distribution.TooManyKeyGroupsAssociatedToDistribution: <p>The number of key groups referenced by this distribution is more than the maximum allowed. For more information, see <a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html">Quotas</a> (formerly known as limits) in the <i>Amazon CloudFront Developer Guide</i>.</p>
        capo_cloudfront.errors.too_many_lambda_function_associations.TooManyLambdaFunctionAssociations: <p>Your request contains more Lambda@Edge function associations than are allowed per distribution.</p>
        capo_cloudfront.errors.too_many_origin_custom_headers.TooManyOriginCustomHeaders: <p>Your request contains too many origin custom headers.</p>
        capo_cloudfront.errors.too_many_origin_groups_per_distribution.TooManyOriginGroupsPerDistribution: <p>Processing your request would cause you to exceed the maximum number of origin groups allowed.</p>
        capo_cloudfront.errors.too_many_origins.TooManyOrigins: <p>You cannot create more origins for the distribution.</p>
        capo_cloudfront.errors.too_many_query_string_parameters.TooManyQueryStringParameters: <p>Your request contains too many query string parameters.</p>
        capo_cloudfront.errors.too_many_trusted_signers.TooManyTrustedSigners: <p>Your request contains more trusted signers than are allowed per distribution.</p>
        capo_cloudfront.errors.trusted_key_group_does_not_exist.TrustedKeyGroupDoesNotExist: <p>The specified key group does not exist.</p>
        capo_cloudfront.errors.trusted_signer_does_not_exist.TrustedSignerDoesNotExist: <p>One or more of your trusted signers don't exist.</p>
        capo_cloudfront.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_cloudfront.types.update_distribution_request.UpdateDistributionRequest]",
    ) -> OperationResponse[
        "capo_cloudfront.types.update_distribution_result.UpdateDistributionResult"
    ]:
        import capo_cloudfront._operations.cloudfront2020_05_31.update_distribution

        output, http_response = (
            capo_cloudfront._operations.cloudfront2020_05_31.update_distribution.update_distribution(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_cloudfront.types.update_distribution_request.UpdateDistributionRequest",
    ) -> dict[str, Any]:
        import capo_cloudfront.types.update_distribution_request

        return capo_cloudfront.types.update_distribution_request.redact_sensitive(
            input_
        )

    def _redact_output(
        output: "capo_cloudfront.types.update_distribution_result.UpdateDistributionResult",
    ) -> dict[str, Any]:
        import capo_cloudfront.types.update_distribution_result

        return capo_cloudfront.types.update_distribution_result.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "UpdateDistribution",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_cloudfront.types.update_distribution_request.UpdateDistributionRequest = {
        "distribution_config": distribution_config,
        "id": id,
    }
    if if_match is not None:
        input_["if_match"] = if_match

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