Skip to content

create_origin_request_policy

create_origin_request_policy(
    origin_request_policy_config: OriginRequestPolicyConfig,
    *,
    config_overrides: Optional[CloudFrontClientConfig] = None,
) -> CreateOriginRequestPolicyResult

Creates an origin request policy.

After you create an origin request policy, you can attach it to one or more cache behaviors. When it's attached to a cache behavior, the origin request policy determines the values that CloudFront includes in requests that it sends to the origin. Each request that CloudFront sends to the origin includes the following:

  • The request body and the URL path (without the domain name) from the viewer request.

  • The headers that CloudFront automatically includes in every origin request, including Host, User-Agent, and X-Amz-Cf-Id.

  • All HTTP headers, cookies, and URL query strings that are specified in the cache policy or the origin request policy. These can include items from the viewer request and, in the case of headers, additional ones that are added by CloudFront.

CloudFront sends a request when it can't find a valid object in its cache that matches the request. If you want to send values to the origin and also include them in the cache key, use CachePolicy.

For more information about origin request policies, see Controlling origin requests in the Amazon CloudFront Developer Guide.

Parameters:

Raises:

  • AccessDenied –

    Access denied.

  • InconsistentQuantities –

    The value of Quantity and the size of Items don't match.

  • InvalidArgument –

    An argument is invalid.

  • OriginRequestPolicyAlreadyExists –

    An origin request policy with this name already exists. You must provide a unique name. To modify an existing origin request policy, use UpdateOriginRequestPolicy.

  • TooManyCookiesInOriginRequestPolicy –

    The number of cookies in the origin request policy exceeds the maximum. For more information, see Quotas (formerly known as limits) in the Amazon CloudFront Developer Guide.

  • TooManyHeadersInOriginRequestPolicy –

    The number of headers in the origin request policy exceeds the maximum. For more information, see Quotas (formerly known as limits) in the Amazon CloudFront Developer Guide.

  • TooManyOriginRequestPolicies –

    You have reached the maximum number of origin request policies for this Amazon Web Services account. For more information, see Quotas (formerly known as limits) in the Amazon CloudFront Developer Guide.

  • TooManyQueryStringsInOriginRequestPolicy –

    The number of query strings in the origin request policy exceeds the maximum. For more information, see Quotas (formerly known as limits) in the Amazon CloudFront Developer Guide.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_cloudfront/_services/cloud_front.py
def create_origin_request_policy(
    self,
    origin_request_policy_config: "capo_cloudfront.types.origin_request_policy_config.OriginRequestPolicyConfig",
    *,
    config_overrides: Optional[CloudFrontClientConfig] = None,
) -> "capo_cloudfront.types.create_origin_request_policy_result.CreateOriginRequestPolicyResult":
    """<p>Creates an origin request policy.</p> <p>After you create an origin request policy, you can attach it to one or more cache behaviors. When it's attached to a cache behavior, the origin request policy determines the values that CloudFront includes in requests that it sends to the origin. Each request that CloudFront sends to the origin includes the following:</p> <ul> <li> <p>The request body and the URL path (without the domain name) from the viewer request.</p> </li> <li> <p>The headers that CloudFront automatically includes in every origin request, including <code>Host</code>, <code>User-Agent</code>, and <code>X-Amz-Cf-Id</code>.</p> </li> <li> <p>All HTTP headers, cookies, and URL query strings that are specified in the cache policy or the origin request policy. These can include items from the viewer request and, in the case of headers, additional ones that are added by CloudFront.</p> </li> </ul> <p>CloudFront sends a request when it can't find a valid object in its cache that matches the request. If you want to send values to the origin and also include them in the cache key, use <code>CachePolicy</code>.</p> <p>For more information about origin request policies, see <a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-origin-requests.html">Controlling origin requests</a> in the <i>Amazon CloudFront Developer Guide</i>.</p>

    Args:
        origin_request_policy_config: <p>An origin request policy configuration.</p>

    Raises:
        capo_cloudfront.errors.access_denied.AccessDenied: <p>Access denied.</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.origin_request_policy_already_exists.OriginRequestPolicyAlreadyExists: <p>An origin request policy with this name already exists. You must provide a unique name. To modify an existing origin request policy, use <code>UpdateOriginRequestPolicy</code>.</p>
        capo_cloudfront.errors.too_many_cookies_in_origin_request_policy.TooManyCookiesInOriginRequestPolicy: <p>The number of cookies in the origin request policy exceeds the maximum. 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_origin_request_policy.TooManyHeadersInOriginRequestPolicy: <p>The number of headers in the origin request policy exceeds the maximum. 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_origin_request_policies.TooManyOriginRequestPolicies: <p>You have reached the maximum number of origin request policies for this Amazon Web Services account. 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_query_strings_in_origin_request_policy.TooManyQueryStringsInOriginRequestPolicy: <p>The number of query strings in the origin request policy exceeds the maximum. 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.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_cloudfront.types.create_origin_request_policy_request.CreateOriginRequestPolicyRequest]",
    ) -> OperationResponse[
        "capo_cloudfront.types.create_origin_request_policy_result.CreateOriginRequestPolicyResult"
    ]:
        import capo_cloudfront._operations.cloudfront2020_05_31.create_origin_request_policy

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateOriginRequestPolicy")
    )
    input_: capo_cloudfront.types.create_origin_request_policy_request.CreateOriginRequestPolicyRequest = {
        "origin_request_policy_config": origin_request_policy_config
    }

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