Skip to content

cloudfront path pattern is not being triggered

0

I have a cloudfront distro with two s3 buckets origins (see image) enter image description here

Enter image description here

each pointing to a different UI. I have made both publicly accessible for testing, so I checked to make sure when I directly visit the s3 bucket URL, I can view the pages and both are working fine. Here are the s3 buckets - at the time of writing the stack is still available.

http://redrobottest-translatorservicestackstaticwebsitede-ygzeqwacyepi.s3-website-us-east-1.amazonaws.com/ and http://redrobottest-websitebucket75c24d94-xs5l6nhzgq6e.s3-website-us-east-1.amazonaws.com/

And I have defined path patterns, to route traffic to either s3 bucket depending if the pattern has matched. You can see the associated origins in the table list.

Enter image description here

but when I go to the url:

https://d11ckeh3gftpjv.cloudfront.net/learn/apps/translator

it still trigger the default path which is this:

https://d11ckeh3gftpjv.cloudfront.net

I am not sure how to debug cloudfront - any gueses to what I am doing wrong? I have tried different pattern formats as well:

/learn/app/* learn/app/* /learn/app/translate/*

and none worked

2 Answers
3

Have you tried invalidating the cache in CloudFront? It's a good idea to do so before making any additions or changes to your distribution. If you tested the default path before adding the /learn/apps/translator path, then CloudFront may have cached the default UI and thus will return stale information until the cache's data is refreshed or cleared. Hope this helps out!

AWS

answered 2 years ago

EXPERT

reviewed 2 years ago

EXPERT

reviewed 2 years ago

  • I didn't know about the invalidation function so I am issuing invalidations on each path change - I ran an invalidation to path /* hopefully that works. but I disabled caching for all origins, anyways this is great info thank you!

0

The screenshot doesn't show the path pattern you've configured, but it has to have the wildcard at the end to match the prefix. The slash / at the beginning is allowed but not required; it'll work the same either way. This documentation article explains it in detail: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesPathPattern

On a general note, you shouldn't configure S3 buckets as publicly accessible and enable them for static website hosting. Instead, you should disable static website hosting for the S3 bucket, set CloudFront to use Origin Access Control to access your bucket directly as an S3 origin (and not a custom origin pointing to the s3-website hostname), and grant access in the bucket policy to the OAC you configured CloudFront to use.

Note specifically that you must disable static website hosting before configuring OAC access for it. The two features won't work together.

The procedure for configuring an S3 bucket as a native origin for CloudFront using OAC is explained in detail in documentation: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/GettingStarted.SimpleDistribution.html

Once you have that working, you should enable Block Public Access (BPA) for the bucket: https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-control-block-public-access.html. If no other buckets in the account are accessed publicly, you should also enable the BPA setting at the account level.

EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.