-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Viewer Protocol Policy in Behavior for Cloudfront #7086
Comments
@prax0724 we can use 'viewerProtocolPolicy' attribute and set it to one of |
@bpcrao |
yes @prax0724 |
It is available at CloudFrontWebDistribution but not for Behavior. On the console we have the option of setting it for each individual Behavior and not at Cloudfront level. For our use case we are not impacted by this but just in case for others. |
@prax0724 Got it - thanks for reporting 👍 |
I think this is a bug.
const myWebDistribution = new cloudfront.Distribution(this, 'myDist', {
defaultBehavior: {
origin: cloudfront.Origin.fromBucket(myBucket),
allowedMethods: AllowedMethods.ALLOW_ALL,
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
}
}); But it's not in type declarations export interface AddBehaviorOptions {
/**
* HTTP methods to allow for this behavior.
*
* @default - GET and HEAD
*/
readonly allowedMethods?: AllowedMethods;
/**
* Whether CloudFront will forward query strings to the origin.
* If this is set to true, CloudFront will forward all query parameters to the origin, and cache
* based on all parameters. See `forwardQueryStringCacheKeys` for a way to limit the query parameters
* CloudFront caches on.
*
* @default false
*/
readonly forwardQueryString?: boolean;
/**
* A set of query string parameter names to use for caching if `forwardQueryString` is set to true.
*
* @default []
*/
readonly forwardQueryStringCacheKeys?: string[];
}
/**
* Options for creating a new behavior.
*
* @experimental
*/
export interface BehaviorOptions extends AddBehaviorOptions {
/**
* The origin that you want CloudFront to route requests to when they match this behavior.
*/
readonly origin: Origin;
} |
Just to clarify, the feature request was opened in relation to the What @ivawzh is referring to is the new @njlynch Can you confirm there is indeed a documentation in the new construct? In any case, this will be added to the new As far as supporting this for the old Thanks |
…er protocol, and smooth streaming Adds support for many of the missing properties for controlling behaviors on the new Distribution construct. Also removed (currently unavailable) properties from the README. The remaining properties will come in a follow-up PR. They were not included in this PR due to either being blocked by the latest CloudFormation spec merge, or are still being prioritized (e.g., fieldLevelEncryption). related #7086 related #9107
ivawzh@ / iliapolo@ - The documentation for the new Distribution construct was referencing the ViewerProtocolPolicy prior to it being available; rather than update the documentation, I've added the missing properties in #9411 (and updated the README where it still references missing attributes). |
…er protocol, and smooth streaming (#9411) Adds support for many of the missing properties for controlling behaviors on the new Distribution construct. Also removed (currently unavailable) properties from the README. The remaining properties will come in a follow-up PR. They were not included in this PR due to either being blocked by the latest CloudFormation spec merge, or are still being prioritized (e.g., fieldLevelEncryption). related #7086 related #9107 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
…er protocol, and smooth streaming (#9411) Adds support for many of the missing properties for controlling behaviors on the new Distribution construct. Also removed (currently unavailable) properties from the README. The remaining properties will come in a follow-up PR. They were not included in this PR due to either being blocked by the latest CloudFormation spec merge, or are still being prioritized (e.g., fieldLevelEncryption). related #7086 related #9107 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
…er protocol, and smooth streaming (aws#9411) Adds support for many of the missing properties for controlling behaviors on the new Distribution construct. Also removed (currently unavailable) properties from the README. The remaining properties will come in a follow-up PR. They were not included in this PR due to either being blocked by the latest CloudFormation spec merge, or are still being prioritized (e.g., fieldLevelEncryption). related aws#7086 related aws#9107 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
I encountered the same problem and is there any update? The new EDIT: A hacking solution: let dist = distribution.node.defaultChild as cloudfront.CfnDistribution;
let conf = dist.distributionConfig as cloudfront.CfnDistribution.DistributionConfigProperty;
let cacheBehaviors = conf.cacheBehaviors as cloudfront.CfnDistribution.CacheBehaviorProperty[];
let behavior = cacheBehaviors[0];
cacheBehaviors[0] = {
...cacheBehaviors[0],
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.ALLOW_ALL,
} as cloudfront.CfnDistribution.CacheBehaviorProperty; |
It seems that this issue won't be fixed? |
A possible fix for this with API changes: diff --git a/packages/@aws-cdk/aws-cloudfront/lib/web-distribution.ts b/packages/@aws-cdk/aws-cloudfront/lib/web-distribution.ts
index 29a63fd681bb..ab2fbbd44b03 100644
--- a/packages/@aws-cdk/aws-cloudfront/lib/web-distribution.ts
+++ b/packages/@aws-cdk/aws-cloudfront/lib/web-distribution.ts
@@ -454,6 +454,12 @@ export interface Behavior {
*/
readonly functionAssociations?: FunctionAssociation[];
+ /**
+ * The viewer policy for this behavior.
+ *
+ * @default - the distribution wide viewer protocol policy will be used
+ */
+ readonly viewerProtocolPolicy?: ViewerProtocolPolicy;
}
export interface LambdaFunctionAssociation {
@@ -992,7 +998,7 @@ export class CloudFrontWebDistribution extends cdk.Resource implements IDistribu
trustedKeyGroups: input.trustedKeyGroups?.map(key => key.keyGroupId),
trustedSigners: input.trustedSigners,
targetOriginId: input.targetOriginId,
- viewerProtocolPolicy: protoPolicy || ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
+ viewerProtocolPolicy: input.viewerProtocolPolicy || protoPolicy || ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
};
if (!input.isDefaultBehavior) {
toReturn = Object.assign(toReturn, { pathPattern: input.pathPattern }); |
This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
The Behavior interface do not have any property to set Viewer Protocol Policy , although it can be set from AWS console.
Please add support for this property.
https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudfront.Behavior.html
The text was updated successfully, but these errors were encountered: