@@ -494,10 +494,44 @@ Resources:
494494 Type : AWS::CloudFront::CachePolicy
495495 Properties :
496496 CachePolicyConfig :
497- DefaultTTL : 60 # 1 day (default)
497+ DefaultTTL : 86400 # 1 day (default)
498+ MaxTTL : 31536000 # 1 year (default)
499+ MinTTL : 0
500+ Name : !Sub ${AWS::StackName}-next-static-cache-policy
501+ ParametersInCacheKeyAndForwardedToOrigin :
502+ CookiesConfig :
503+ CookieBehavior : none
504+ EnableAcceptEncodingBrotli : true
505+ EnableAcceptEncodingGzip : true
506+ HeadersConfig :
507+ HeaderBehavior : none
508+ QueryStringsConfig :
509+ QueryStringBehavior : none
510+ StaticCachePolicy :
511+ Type : AWS::CloudFront::CachePolicy
512+ Properties :
513+ CachePolicyConfig :
514+ DefaultTTL : 86400 # 1 day (default)
498515 MaxTTL : 31536000 # 1 year (default)
499- MinTTL : 30 # 5 minutes
500- Name : !Sub ${AWS::StackName}-frontend-cache-policy
516+ MinTTL : 0
517+ Name : !Sub ${AWS::StackName}-next-static-cache-policy
518+ ParametersInCacheKeyAndForwardedToOrigin :
519+ CookiesConfig :
520+ CookieBehavior : none
521+ EnableAcceptEncodingBrotli : true
522+ EnableAcceptEncodingGzip : true
523+ HeadersConfig :
524+ HeaderBehavior : none
525+ QueryStringsConfig :
526+ QueryStringBehavior : none
527+ ApiCachePolicy :
528+ Type : AWS::CloudFront::CachePolicy
529+ Properties :
530+ CachePolicyConfig :
531+ DefaultTTL : 0
532+ MaxTTL : 31536000 # 1 year (default)
533+ MinTTL : 0
534+ Name : !Sub ${AWS::StackName}-next-static-cache-policy
501535 ParametersInCacheKeyAndForwardedToOrigin :
502536 CookiesConfig :
503537 CookieBehavior : none
@@ -508,7 +542,45 @@ Resources:
508542 Headers :
509543 - host
510544 QueryStringsConfig :
511- QueryStringBehavior : none
545+ QueryStringBehavior : all
546+ NextDataCachePolicy :
547+ Type : AWS::CloudFront::CachePolicy
548+ Properties :
549+ CachePolicyConfig :
550+ DefaultTTL : 0
551+ MaxTTL : 31536000 # 1 year (default)
552+ MinTTL : 0
553+ Name : !Sub ${AWS::StackName}-next-static-cache-policy
554+ ParametersInCacheKeyAndForwardedToOrigin :
555+ CookiesConfig :
556+ CookieBehavior : none
557+ EnableAcceptEncodingBrotli : true
558+ EnableAcceptEncodingGzip : true
559+ HeadersConfig :
560+ HeaderBehavior : whitelist
561+ Headers :
562+ - host
563+ QueryStringsConfig :
564+ QueryStringBehavior : all
565+ NextImageCachePolicy :
566+ Type : AWS::CloudFront::CachePolicy
567+ Properties :
568+ CachePolicyConfig :
569+ DefaultTTL : 60
570+ MaxTTL : 31536000 # 1 year (default)
571+ MinTTL : 0
572+ Name : !Sub ${AWS::StackName}-next-static-cache-policy
573+ ParametersInCacheKeyAndForwardedToOrigin :
574+ CookiesConfig :
575+ CookieBehavior : none
576+ EnableAcceptEncodingBrotli : true
577+ EnableAcceptEncodingGzip : true
578+ HeadersConfig :
579+ HeaderBehavior : whitelist
580+ Headers :
581+ - accept
582+ QueryStringsConfig :
583+ QueryStringBehavior : all
512584 AggresiveCachePolicy :
513585 Type : AWS::CloudFront::CachePolicy
514586 Properties :
@@ -559,15 +631,51 @@ Resources:
559631 - [theworld.org]
560632 - [stag.theworld.org]
561633 CacheBehaviors :
562- # WordPress Preview
563- - AllowedMethods : [GET, HEAD, OPTIONS ]
564- CachedMethods : [GET, HEAD, OPTIONS ]
634+ # Next.js static
635+ - AllowedMethods : [GET, HEAD]
636+ CachedMethods : [GET, HEAD]
565637 CachePolicyId : !GetAtt NextStaticCachePolicy.Id
566638 Compress : true
567639 OriginRequestPolicyId : !GetAtt OriginRequestPolicy.Id
568640 PathPattern : " /_next/static/*"
569641 TargetOriginId : frontend-ecs
570642 ViewerProtocolPolicy : redirect-to-https
643+ # Static
644+ - AllowedMethods : [GET, HEAD]
645+ CachedMethods : [GET, HEAD]
646+ CachePolicyId : !GetAtt StaticCachePolicy.Id
647+ Compress : true
648+ OriginRequestPolicyId : !GetAtt OriginRequestPolicy.Id
649+ PathPattern : " /static/*"
650+ TargetOriginId : frontend-ecs
651+ ViewerProtocolPolicy : redirect-to-https
652+ # API
653+ - AllowedMethods : [GET, HEAD, OPTIONS]
654+ CachedMethods : [GET, HEAD, OPTIONS]
655+ CachePolicyId : !GetAtt ApiCachePolicy.Id
656+ Compress : true
657+ OriginRequestPolicyId : !GetAtt OriginRequestPolicy.Id
658+ PathPattern : " /api/*"
659+ TargetOriginId : frontend-ecs
660+ ViewerProtocolPolicy : redirect-to-https
661+ # Next.js data
662+ - AllowedMethods : [GET, HEAD, OPTIONS]
663+ CachedMethods : [GET, HEAD, OPTIONS]
664+ CachePolicyId : !GetAtt NextDataCachePolicy.Id
665+ Compress : true
666+ OriginRequestPolicyId : !GetAtt OriginRequestPolicy.Id
667+ PathPattern : " /_next/data/*"
668+ TargetOriginId : frontend-ecs
669+ ViewerProtocolPolicy : redirect-to-https
670+ # Next.js image
671+ - AllowedMethods : [GET, HEAD, OPTIONS]
672+ CachedMethods : [GET, HEAD, OPTIONS]
673+ CachePolicyId : !GetAtt NextImageCachePolicy.Id
674+ Compress : true
675+ OriginRequestPolicyId : !GetAtt OriginRequestPolicy.Id
676+ PathPattern : " /_next/image*"
677+ TargetOriginId : frontend-ecs
678+ ViewerProtocolPolicy : redirect-to-https
571679 Comment : !Sub The World ${EnvironmentType} frontend
572680 ConnectionMode : direct
573681 DefaultCacheBehavior :
0 commit comments