Skip to content

Commit 92f97b6

Browse files
committed
use a custom cloudfront cache policy
1 parent 5817554 commit 92f97b6

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

cloudformation/main.yml

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -633,14 +633,8 @@ Resources:
633633
CachedMethods:
634634
- GET
635635
- HEAD
636-
ForwardedValues:
637-
QueryString: true
638-
QueryStringCacheKeys:
639-
- host
640-
- ts
641-
- upcomingOnly
642-
Cookies:
643-
Forward: none
636+
CachePolicyId: !Ref CloudfrontCachePolicy
637+
OriginRequestPolicyId: b689b0a8-53d0-40ab-baf2-68738e2966ac # all except host
644638
- PathPattern: "/api/v1/events/*"
645639
TargetOriginId: ApiGatewayOrigin
646640
ViewerProtocolPolicy: redirect-to-https
@@ -655,14 +649,8 @@ Resources:
655649
CachedMethods:
656650
- GET
657651
- HEAD
658-
ForwardedValues:
659-
QueryString: true
660-
QueryStringCacheKeys:
661-
- host
662-
- ts
663-
- upcomingOnly
664-
Cookies:
665-
Forward: none
652+
CachePolicyId: !Ref CloudfrontCachePolicy
653+
OriginRequestPolicyId: b689b0a8-53d0-40ab-baf2-68738e2966ac # all except host
666654
- PathPattern: "/api/*"
667655
TargetOriginId: ApiGatewayOrigin
668656
ViewerProtocolPolicy: redirect-to-https
@@ -707,6 +695,31 @@ Resources:
707695
Action: s3:GetObject
708696
Resource: !Sub "${AppFrontendS3Bucket.Arn}/*"
709697

698+
CloudfrontCachePolicy:
699+
Type: AWS::CloudFront::CachePolicy
700+
Properties:
701+
CachePolicyConfig:
702+
Name: UseOriginCacheControlHeaders-QueryStrings-NoCookies
703+
Comment: "Policy for origins that return Cache-Control headers and serve different content based on query strings but dont require cookies."
704+
DefaultTTL: 0
705+
MaxTTL: 31536000
706+
MinTTL: 0
707+
ParametersInCacheKeyAndForwardedToOrigin:
708+
EnableAcceptEncodingGzip: true
709+
EnableAcceptEncodingBrotli: true
710+
HeadersConfig:
711+
HeaderBehavior: whitelist
712+
Headers:
713+
- x-method-override
714+
- origin
715+
- host
716+
- x-http-method
717+
- x-http-method-override
718+
QueryStringsConfig:
719+
QueryStringBehavior: all
720+
CookiesConfig:
721+
CookieBehavior: none
722+
710723
Outputs:
711724
DomainName:
712725
Description: Domain name that the UI is hosted at

0 commit comments

Comments
 (0)