Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gazzoy's avatar

What is a best(or recommended) cach policy for CloudFront

I have a question about deploying Laravel on AWS behind CloudFront.

Basically, I deploy Laravel on AWS like CloudFront -> ALB -> Fargate. In that case, as far as I'm concerned, in order to keep users's session safe, we need to set CachePolicy on CloudFront.

Below is my CloudFormation code to build such CachePolicy, but not too sure if its a right setting. So could you tell me about a best practice or recommended CachePolicy for this?

    CachePolicyApp:
      Type: AWS::CloudFront::CachePolicy
      Properties:
        CachePolicyConfig:
            Name: myCachePolicy
            Comment: myCachePolicy
            DefaultTTL: 86400
            MaxTTL: 31536000
            MinTTL: 1
            ParametersInCacheKeyAndForwardedToOrigin:
              EnableAcceptEncodingBrotli: true
              EnableAcceptEncodingGzip: true
              HeadersConfig:
                HeaderBehavior: whitelist
                Headers:
                  - Origin
                  - Authorization
                  - Host
                  - CloudFront-Forwarded-Proto
              CookiesConfig:
                CookieBehavior: whitelist
                Cookies:
                  - laravel_session
              QueryStringsConfig:
                QueryStringBehavior: none
0 likes
3 replies
gazzoy's avatar

Does anybody have any thoughts on this?

martinbean's avatar

@gazzoy Well what are you actually using CloudFront for? You typically only use a CDN like CloudFront for caching static assets like images, stylesheets, etc.

gazzoy's avatar

@martinbean Thanks for your reply! I understand the basic usage for Cloudfront, but basically I'm trying to use CloudFront for:

  • Blocking malicious requests such as DDOS, with less effort
  • Low latency distribution, with less effort
  • Manage SSL easily. I beliveve using Cloudfront is much easer compared to setting up SSL certs on each web servers
  • And, caching static files of course.

But, to be honest, I'm not very familiar with setting up Laravel with AWS, so don't we put Cloudfront in case we deploy Laravel on AWS in most cases?

I saw some articles say its a kind of best practice to put Cloudfront in front of AWS stacks, but I'm not too sure about what the actual best practice for setup Laravel on AWS.

Please or to participate in this conversation.