aws-cdk-lib.aws_cloudfront.OriginRequestPolicy

class OriginRequestPolicy (construct)

LanguageType name
.NETAmazon.CDK.AWS.CloudFront.OriginRequestPolicy
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awscloudfront#OriginRequestPolicy
Javasoftware.amazon.awscdk.services.cloudfront.OriginRequestPolicy
Pythonaws_cdk.aws_cloudfront.OriginRequestPolicy
TypeScript (source)aws-cdk-lib » aws_cloudfront » OriginRequestPolicy

Implements IConstruct, IDependable, IResource, IOriginRequestPolicy

A Origin Request Policy configuration.

Example

// Using an existing origin request policy for a Distribution
declare const bucketOrigin: origins.S3Origin;
new cloudfront.Distribution(this, 'myDistManagedPolicy', {
  defaultBehavior: {
    origin: bucketOrigin,
    originRequestPolicy: cloudfront.OriginRequestPolicy.CORS_S3_ORIGIN,
  },
});

Initializer

new OriginRequestPolicy(scope: Construct, id: string, props?: OriginRequestPolicyProps)

Parameters

  • scope Construct
  • id string
  • props OriginRequestPolicyProps

Construct Props

NameTypeDescription
comment?stringA comment to describe the origin request policy.
cookieBehavior?OriginRequestCookieBehaviorThe cookies from viewer requests to include in origin requests.
headerBehavior?OriginRequestHeaderBehaviorThe HTTP headers to include in origin requests.
originRequestPolicyName?stringA unique name to identify the origin request policy.
queryStringBehavior?OriginRequestQueryStringBehaviorThe URL query strings from viewer requests to include in origin requests.

comment?

Type: string (optional, default: no comment)

A comment to describe the origin request policy.


cookieBehavior?

Type: OriginRequestCookieBehavior (optional, default: OriginRequestCookieBehavior.none())

The cookies from viewer requests to include in origin requests.


headerBehavior?

Type: OriginRequestHeaderBehavior (optional, default: OriginRequestHeaderBehavior.none())

The HTTP headers to include in origin requests.

These can include headers from viewer requests and additional headers added by CloudFront.


originRequestPolicyName?

Type: string (optional, default: generated from the id)

A unique name to identify the origin request policy.

The name must only include '-', '_', or alphanumeric characters.


queryStringBehavior?

Type: OriginRequestQueryStringBehavior (optional, default: OriginRequestQueryStringBehavior.none())

The URL query strings from viewer requests to include in origin requests.

Properties

NameTypeDescription
envResourceEnvironmentThe environment this resource belongs to.
nodeNodeThe tree node.
originRequestPolicyIdstringThe ID of the origin request policy.
stackStackThe stack in which this resource is defined.
static ALL_VIEWERIOriginRequestPolicyThis policy includes all values (query strings, headers, and cookies) in the viewer request.
static ALL_VIEWER_AND_CLOUDFRONT_2022IOriginRequestPolicyThis policy includes all values (headers, cookies, and query strings) in the viewer request, and all CloudFront headers that were released through June 2022 (CloudFront headers released after June 2022 are not included).
static ALL_VIEWER_EXCEPT_HOST_HEADERIOriginRequestPolicyThis policy includes all values (query strings, and cookies) except the header in the viewer request.
static CORS_CUSTOM_ORIGINIOriginRequestPolicyThis policy includes the header that enables cross-origin resource sharing (CORS) requests when the origin is a custom origin.
static CORS_S3_ORIGINIOriginRequestPolicyThis policy includes the headers that enable cross-origin resource sharing (CORS) requests when the origin is an Amazon S3 bucket.
static ELEMENTAL_MEDIA_TAILORIOriginRequestPolicyThis policy is designed for use with an origin that is an AWS Elemental MediaTailor endpoint.
static USER_AGENT_REFERER_HEADERSIOriginRequestPolicyThis policy includes only the User-Agent and Referer headers.

env

Type: ResourceEnvironment

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.


node

Type: Node

The tree node.


originRequestPolicyId

Type: string

The ID of the origin request policy.


stack

Type: Stack

The stack in which this resource is defined.


static ALL_VIEWER

Type: IOriginRequestPolicy

This policy includes all values (query strings, headers, and cookies) in the viewer request.


static ALL_VIEWER_AND_CLOUDFRONT_2022

Type: IOriginRequestPolicy

This policy includes all values (headers, cookies, and query strings) in the viewer request, and all CloudFront headers that were released through June 2022 (CloudFront headers released after June 2022 are not included).


static ALL_VIEWER_EXCEPT_HOST_HEADER

Type: IOriginRequestPolicy

This policy includes all values (query strings, and cookies) except the header in the viewer request.


static CORS_CUSTOM_ORIGIN

Type: IOriginRequestPolicy

This policy includes the header that enables cross-origin resource sharing (CORS) requests when the origin is a custom origin.


static CORS_S3_ORIGIN

Type: IOriginRequestPolicy

This policy includes the headers that enable cross-origin resource sharing (CORS) requests when the origin is an Amazon S3 bucket.


static ELEMENTAL_MEDIA_TAILOR

Type: IOriginRequestPolicy

This policy is designed for use with an origin that is an AWS Elemental MediaTailor endpoint.


static USER_AGENT_REFERER_HEADERS

Type: IOriginRequestPolicy

This policy includes only the User-Agent and Referer headers.

It doesn’t include any query strings or cookies.

Methods

NameDescription
applyRemovalPolicy(policy)Apply the given removal policy to this resource.
toString()Returns a string representation of this construct.
static fromOriginRequestPolicyId(scope, id, originRequestPolicyId)Imports a Origin Request Policy from its id.

applyRemovalPolicy(policy)

public applyRemovalPolicy(policy: RemovalPolicy): void

Parameters

  • policy RemovalPolicy

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).


toString()

public toString(): string

Returns

  • string

Returns a string representation of this construct.


static fromOriginRequestPolicyId(scope, id, originRequestPolicyId)

public static fromOriginRequestPolicyId(scope: Construct, id: string, originRequestPolicyId: string): IOriginRequestPolicy

Parameters

  • scope Construct
  • id string
  • originRequestPolicyId string

Returns

  • IOriginRequestPolicy

Imports a Origin Request Policy from its id.