Skip to content
v2.273.0

OriginRequestPolicy L2 construct ​

A Origin Request Policy configuration.

Example ​

ts
// 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,
  },
});
python
# Using an existing origin request policy for a Distribution
# bucket_origin: origins.S3Origin

cloudfront.Distribution(self, "myDistManagedPolicy",
    default_behavior=cloudfront.BehaviorOptions(
        origin=bucket_origin,
        origin_request_policy=cloudfront.OriginRequestPolicy.CORS_S3_ORIGIN
    )
)
java
// Using an existing origin request policy for a Distribution
S3Origin bucketOrigin;

Distribution.Builder.create(this, "myDistManagedPolicy")
        .defaultBehavior(BehaviorOptions.builder()
                .origin(bucketOrigin)
                .originRequestPolicy(OriginRequestPolicy.CORS_S3_ORIGIN)
                .build())
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
// Using an existing origin request policy for a Distribution
S3Origin bucketOrigin;

new Distribution(this, "myDistManagedPolicy", new DistributionProps {
    DefaultBehavior = new BehaviorOptions {
        Origin = bucketOrigin,
        OriginRequestPolicy = OriginRequestPolicy.CORS_S3_ORIGIN
    }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// Using an existing origin request policy for a Distribution
var bucketOrigin S3Origin

cloudfront.NewDistribution(this, jsii.String("myDistManagedPolicy"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: bucketOrigin,
		OriginRequestPolicy: cloudfront.OriginRequestPolicy_CORS_S3_ORIGIN(),
	},
})

Initializer ​

ts
new OriginRequestPolicy(scope: Construct, id: string, props?: OriginRequestPolicyProps)
python
OriginRequestPolicy(scope: Construct, id: str, props: typing.Optional[OriginRequestPolicyProps] = None)
java
new OriginRequestPolicy(Construct scope, String id, OriginRequestPolicyProps props)
csharp
new OriginRequestPolicy(Construct scope, string id, OriginRequestPolicyProps? props = null)
go
NewOriginRequestPolicy(Scope Construct, Id *string, Props OriginRequestPolicyProps)

Construct Props ​

commentstringcommentstrcommentStringCommentstringComment*string= no comment#
A comment to describe the origin request policy.
cookieBehaviorOriginRequestCookieBehaviorcookie_behaviorOriginRequestCookieBehaviorcookieBehaviorOriginRequestCookieBehaviorCookieBehaviorOriginRequestCookieBehaviorCookieBehaviorOriginRequestCookieBehavior= OriginRequestCookieBehavior.none…#
The cookies from viewer requests to include in origin requests.
default

Default: OriginRequestCookieBehavior.none()

headerBehaviorOriginRequestHeaderBehaviorheader_behaviorOriginRequestHeaderBehaviorheaderBehaviorOriginRequestHeaderBehaviorHeaderBehaviorOriginRequestHeaderBehaviorHeaderBehaviorOriginRequestHeaderBehavior= OriginRequestHeaderBehavior.none…#
The HTTP headers to include in origin requests.

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

default

Default: OriginRequestHeaderBehavior.none()

originRequestPolicyNamestringorigin_request_policy_namestroriginRequestPolicyNameStringOriginRequestPolicyNamestringOriginRequestPolicyName*string= generated from the `id`#
A unique name to identify the origin request policy.

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

queryStringBehaviorOriginRequestQueryStringBehaviorquery_string_behaviorOriginRequestQueryStringBehaviorqueryStringBehaviorOriginRequestQueryStringBehaviorQueryStringBehaviorOriginRequestQueryStringBehaviorQueryStringBehaviorOriginRequestQueryStringBehavior= OriginRequestQueryStringBehavior…#
The URL query strings from viewer requests to include in origin requests.
default

Default: OriginRequestQueryStringBehavior.none()

Properties ​

This policy includes all values (query strings, headers, and cookies) in the viewer request.
ALL_VIEWER_AND_CLOUDFRONT_2022IOriginRequestPolicyall_viewer_and_cloudfront_2022IOriginRequestPolicyALL_VIEWER_AND_CLOUDFRONT_2022IOriginRequestPolicyALL_VIEWER_AND_CLOUDFRONT_2022IOriginRequestPolicyALL_VIEWER_AND_CLOUDFRONT_2022IOriginRequestPolicyrequiredstatic#
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).
ALL_VIEWER_EXCEPT_HOST_HEADERIOriginRequestPolicyall_viewer_except_host_headerIOriginRequestPolicyALL_VIEWER_EXCEPT_HOST_HEADERIOriginRequestPolicyALL_VIEWER_EXCEPT_HOST_HEADERIOriginRequestPolicyALL_VIEWER_EXCEPT_HOST_HEADERIOriginRequestPolicyrequiredstatic#
This policy includes all values (query strings, and cookies) except the header in the viewer request.
CORS_CUSTOM_ORIGINIOriginRequestPolicycors_custom_originIOriginRequestPolicyCORS_CUSTOM_ORIGINIOriginRequestPolicyCORS_CUSTOM_ORIGINIOriginRequestPolicyCORS_CUSTOM_ORIGINIOriginRequestPolicyrequiredstatic#
This policy includes the header that enables cross-origin resource sharing (CORS) requests when the origin is a custom origin.
CORS_S3_ORIGINIOriginRequestPolicycors_s3_originIOriginRequestPolicyCORS_S3_ORIGINIOriginRequestPolicyCORS_S3_ORIGINIOriginRequestPolicyCORS_S3_ORIGINIOriginRequestPolicyrequiredstatic#
This policy includes the headers that enable cross-origin resource sharing (CORS) requests when the origin is an Amazon S3 bucket.
ELEMENTAL_MEDIA_TAILORIOriginRequestPolicyelemental_media_tailorIOriginRequestPolicyELEMENTAL_MEDIA_TAILORIOriginRequestPolicyELEMENTAL_MEDIA_TAILORIOriginRequestPolicyELEMENTAL_MEDIA_TAILORIOriginRequestPolicyrequiredstatic#
This policy is designed for use with an origin that is an AWS Elemental MediaTailor endpoint.
The environment this resource belongs to.
notes

For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.

For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.

HOST_HEADER_ONLYIOriginRequestPolicyhost_header_onlyIOriginRequestPolicyHOST_HEADER_ONLYIOriginRequestPolicyHOST_HEADER_ONLYIOriginRequestPolicyHOST_HEADER_ONLYIOriginRequestPolicyrequiredstatic#
This policy includes only the Host header from the origin request.

It doesn't include any query strings or cookies.

nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
originRequestPolicyIdstringorigin_request_policy_idstroriginRequestPolicyIdStringOriginRequestPolicyIdstringOriginRequestPolicyId*stringrequired#
The ID of the origin request policy.
originRequestPolicyRefOriginRequestPolicyReferenceorigin_request_policy_refOriginRequestPolicyReferenceoriginRequestPolicyRefOriginRequestPolicyReferenceOriginRequestPolicyRefOriginRequestPolicyReferenceOriginRequestPolicyRefOriginRequestPolicyReferencerequired#
A reference to a OriginRequestPolicy resource.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#
Uniquely identifies this class.
stackStackstackStackstackStackStackStackStackStackrequired#
The stack in which this resource is defined.
USER_AGENT_REFERER_HEADERSIOriginRequestPolicyuser_agent_referer_headersIOriginRequestPolicyUSER_AGENT_REFERER_HEADERSIOriginRequestPolicyUSER_AGENT_REFERER_HEADERSIOriginRequestPolicyUSER_AGENT_REFERER_HEADERSIOriginRequestPolicyrequiredstatic#
This policy includes only the User-Agent and Referer headers.

It doesn’t include any query strings or cookies.

Methods ​

applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#
Override the cross-stack reference strength for this resource.
notes · 1 parameter

When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.

Parameters

  • strengthstrengthstrengthstrengthStrength — - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#
Apply the given removal policy to this resource.
notes

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

fromOriginRequestPolicyId(scope: Construct, id: string, originRequestPolicyId: string): IOriginRequestPolicy@staticmethod def from_origin_request_policy_id(scope: Construct, id: str, origin_request_policy_id: str) -> IOriginRequestPolicypublic static IOriginRequestPolicy fromOriginRequestPolicyId(Construct scope, String id, String originRequestPolicyId)public static IOriginRequestPolicy FromOriginRequestPolicyId(Construct scope, string id, string originRequestPolicyId)func FromOriginRequestPolicyId(Scope Construct, Id *string, OriginRequestPolicyId *string) IOriginRequestPolicystatic#
Imports a Origin Request Policy from its id.
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Construct.

isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#
Returns true if the construct was created by CDK, and false otherwise.
isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#
Check whether the given construct is a Resource.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.