-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feature/do 1357 cdk v2 templating #1395
Changes from 8 commits
c7494fb
4b29687
b76c938
55329db
9e12264
6fe6db4
c6d9aad
7f97cb6
cf37d62
3e1954c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,27 +2,27 @@ import { Construct } from "constructs"; | |
import { CfnOutput, Duration, RemovalPolicy } from "aws-cdk-lib"; | ||
import { Certificate } from "aws-cdk-lib/aws-certificatemanager"; | ||
import { | ||
BehaviorOptions, | ||
CacheHeaderBehavior, | ||
CachePolicy, | ||
CfnDistribution, | ||
Distribution, | ||
DistributionProps, | ||
EdgeLambda, | ||
ErrorResponse, | ||
HttpVersion, | ||
IDistribution, | ||
IResponseHeadersPolicy, | ||
IOriginAccessIdentity, | ||
LambdaEdgeEventType, | ||
OriginAccessIdentity, | ||
OriginRequestHeaderBehavior, | ||
OriginRequestPolicy, | ||
PriceClass, | ||
ResponseHeadersPolicy, | ||
SecurityPolicyProtocol, | ||
SSLMethod, | ||
ViewerProtocolPolicy, | ||
BehaviorOptions, | ||
ErrorResponse, | ||
EdgeLambda, | ||
CfnDistribution, | ||
OriginRequestPolicy, | ||
CachePolicy, | ||
OriginRequestHeaderBehavior, | ||
CacheHeaderBehavior, | ||
IResponseHeadersPolicy, | ||
LambdaEdgeEventType, | ||
OriginAccessIdentity, | ||
IDistribution, | ||
IOriginAccessIdentity, | ||
} from "aws-cdk-lib/aws-cloudfront"; | ||
import { HttpOrigin, S3Origin } from "aws-cdk-lib/aws-cloudfront-origins"; | ||
import { | ||
|
@@ -246,6 +246,16 @@ export interface StaticHostingProps { | |
*/ | ||
defaultBehaviorCachePolicy?: CachePolicy; | ||
|
||
/** | ||
* Additional headers to include in OriginRequestHeaderBehavior | ||
*/ | ||
additionalDefaultOriginRequestHeaders?: string[]; | ||
|
||
/** | ||
* Additional headers to include in CacheHeaderBehavior | ||
*/ | ||
additionalDefaultCacheKeyHeaders?: string[]; | ||
|
||
/** | ||
* After switching constructs, you need to maintain the same logical ID | ||
* for the underlying CfnDistribution if you wish to avoid the deletion | ||
|
@@ -425,23 +435,39 @@ export class StaticHosting extends Construct { | |
}); | ||
let backendOrigin = undefined; | ||
|
||
const originRequestHeaderBehaviorAllowList = [ | ||
"x-forwarded-host", // Consumed by OriginRequest Lambda@Edge for Feature Environment functionality. | ||
"x-request-prerender", // Consumed by OriginRequest Lambda@Edge to determine if this request needs to be send to Prerender service rather than other origins. | ||
"x-prerender-host", // Consumed by OriginRequest Lambda@Edge, only when x-request-prerender header is set. Prerender service will send request to this host. | ||
"x-prerender", // Consumed, if configured, by origin's custom features, such as GeoRedirection, the behave of which should depend on whether the request is from an end user. | ||
"x-prerender-user-agent", // Consumed by Prerender service for logging original user agent rather than CloudFront's | ||
]; | ||
TheOrangePuff marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (props.additionalDefaultOriginRequestHeaders) { | ||
props.additionalDefaultOriginRequestHeaders.forEach(header => { | ||
originRequestHeaderBehaviorAllowList.push(header); | ||
}); | ||
} | ||
const originRequestPolicy = | ||
props.defaultBehaviorRequestPolicy || | ||
new OriginRequestPolicy(this, "S3OriginRequestPolicy", { | ||
headerBehavior: OriginRequestHeaderBehavior.allowList( | ||
"x-forwarded-host", | ||
"x-request-prerender", | ||
"x-prerender" | ||
...originRequestHeaderBehaviorAllowList | ||
), | ||
}); | ||
|
||
const cacheHeaderBehaviorAllowList = [ | ||
"x-forwarded-host", // Origin response may vary depending on the domain/path based on Feature Environment | ||
"x-prerender", // Origin response may vary depending on whether the request is from end user or prerender service. | ||
]; | ||
if (props.additionalDefaultCacheKeyHeaders) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment about the spread operator here |
||
props.additionalDefaultCacheKeyHeaders.forEach(header => { | ||
cacheHeaderBehaviorAllowList.push(header); | ||
}); | ||
} | ||
const originCachePolicy = | ||
props.defaultBehaviorCachePolicy || | ||
new CachePolicy(this, "S3OriginCachePolicy", { | ||
headerBehavior: CacheHeaderBehavior.allowList( | ||
"x-forwarded-host", | ||
"x-request-prerender", | ||
"x-prerender" | ||
...cacheHeaderBehaviorAllowList | ||
), | ||
enableAcceptEncodingBrotli: true, | ||
enableAcceptEncodingGzip: true, | ||
|
@@ -479,7 +505,7 @@ export class StaticHosting extends Construct { | |
origin: s3Origin, | ||
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS, | ||
edgeLambdas: defaultBehaviorEdgeLambdas, | ||
originRequestPolicy: originRequestPolicy, | ||
originRequestPolicy, | ||
cachePolicy: originCachePolicy, | ||
responseHeadersPolicy: responseHeadersPolicy, | ||
}; | ||
|
@@ -540,7 +566,7 @@ export class StaticHosting extends Construct { | |
} | ||
|
||
const distributionProps: DistributionProps = { | ||
domainNames: domainNames, | ||
domainNames, | ||
webAclId: props.webAclArn, | ||
comment: props.comment, | ||
defaultRootObject: defaultRootObject, | ||
|
@@ -557,8 +583,8 @@ export class StaticHosting extends Construct { | |
"DomainCertificate", | ||
props.certificateArn | ||
), | ||
defaultBehavior: defaultBehavior, | ||
additionalBehaviors: additionalBehaviors, | ||
defaultBehavior, | ||
additionalBehaviors, | ||
errorResponses: props.enableErrorConfig ? errorResponses : [], | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be changed to:
I think it's just a little cleaner