Skip to content

copy_distribution

copy_distribution(
    primary_distribution_id: string,
    caller_reference: string,
    *,
    config_overrides: Optional[CloudFrontClientConfig] = None,
    staging: Optional[boolean] = None,
    if_match: Optional[string] = None,
    enabled: Optional[boolean] = None,
) -> CopyDistributionResult

Creates a staging distribution using the configuration of the provided primary distribution. A staging distribution is a copy of an existing distribution (called the primary distribution) that you can use in a continuous deployment workflow.

After you create a staging distribution, you can use UpdateDistribution to modify the staging distribution's configuration. Then you can use CreateContinuousDeploymentPolicy to incrementally move traffic to the staging distribution.

This API operation requires the following IAM permissions:

Parameters:

  • primary_distribution_id (string) –

    The identifier of the primary distribution whose configuration you are copying. To get a distribution ID, use ListDistributions.

  • staging (Optional[boolean], default: None ) –

    The type of distribution that your primary distribution will be copied to. The only valid value is True, indicating that you are copying to a staging distribution.

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

    The version identifier of the primary distribution whose configuration you are copying. This is the ETag value returned in the response to GetDistribution and GetDistributionConfig.

  • caller_reference (string) –

    A value that uniquely identifies a request to create a resource. This helps to prevent CloudFront from creating a duplicate resource if you accidentally resubmit an identical request.

  • enabled (Optional[boolean], default: None ) –

    A Boolean flag to specify the state of the staging distribution when it's created. When you set this value to True, the staging distribution is enabled. When you set this value to False, the staging distribution is disabled.

    If you omit this field, the default value is True.

Raises:

Source code in docs_src/capo_cloudfront/_services/cloud_front.py
def copy_distribution(
    self,
    primary_distribution_id: "capo_cloudfront.types.string.string",
    caller_reference: "capo_cloudfront.types.string.string",
    *,
    config_overrides: Optional[CloudFrontClientConfig] = None,
    staging: Optional["capo_cloudfront.types.boolean.boolean"] = None,
    if_match: Optional["capo_cloudfront.types.string.string"] = None,
    enabled: Optional["capo_cloudfront.types.boolean.boolean"] = None,
) -> "capo_cloudfront.types.copy_distribution_result.CopyDistributionResult":
    """<p>Creates a staging distribution using the configuration of the provided primary distribution. A staging distribution is a copy of an existing distribution (called the primary distribution) that you can use in a continuous deployment workflow.</p> <p>After you create a staging distribution, you can use <code>UpdateDistribution</code> to modify the staging distribution's configuration. Then you can use <code>CreateContinuousDeploymentPolicy</code> to incrementally move traffic to the staging distribution.</p> <p>This API operation requires the following IAM permissions:</p> <ul> <li> <p> <a href="https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_GetDistribution.html">GetDistribution</a> </p> </li> <li> <p> <a href="https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_CreateDistribution.html">CreateDistribution</a> </p> </li> <li> <p> <a href="https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_CopyDistribution.html">CopyDistribution</a> </p> </li> </ul>

    Args:
        primary_distribution_id: <p>The identifier of the primary distribution whose configuration you are copying. To get a distribution ID, use <code>ListDistributions</code>.</p>
        staging: <p>The type of distribution that your primary distribution will be copied to. The only valid value is <code>True</code>, indicating that you are copying to a staging distribution.</p>
        if_match: <p>The version identifier of the primary distribution whose configuration you are copying. This is the <code>ETag</code> value returned in the response to <code>GetDistribution</code> and <code>GetDistributionConfig</code>.</p>
        caller_reference: <p>A value that uniquely identifies a request to create a resource. This helps to prevent CloudFront from creating a duplicate resource if you accidentally resubmit an identical request.</p>
        enabled: <p>A Boolean flag to specify the state of the staging distribution when it's created. When you set this value to <code>True</code>, the staging distribution is enabled. When you set this value to <code>False</code>, the staging distribution is disabled.</p> <p>If you omit this field, the default value is <code>True</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.distribution_already_exists.DistributionAlreadyExists: <p>The caller reference you attempted to create the distribution with is associated with another distribution.</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.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_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.InvalidOrigin: <p>The Amazon S3 origin server specified does not refer to a valid Amazon S3 bucket.</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_protocol_settings.InvalidProtocolSettings: <p>You cannot specify SSLv3 as the minimum protocol version if you only want to support only clients that support Server Name Indication (SNI).</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_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.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.TooManyDistributions: <p>Processing your request would cause you to exceed the maximum number of distributions allowed.</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.copy_distribution_request.CopyDistributionRequest]",
    ) -> OperationResponse[
        "capo_cloudfront.types.copy_distribution_result.CopyDistributionResult"
    ]:
        import capo_cloudfront._operations.cloudfront2020_05_31.copy_distribution

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

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

        return capo_cloudfront.types.copy_distribution_result.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("CopyDistribution", redact_output=_redact_output),
    )
    input_: capo_cloudfront.types.copy_distribution_request.CopyDistributionRequest = {
        "primary_distribution_id": primary_distribution_id,
        "caller_reference": caller_reference,
    }
    if staging is not None:
        input_["staging"] = staging
    if if_match is not None:
        input_["if_match"] = if_match
    if enabled is not None:
        input_["enabled"] = enabled

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