By using AWS re:Post, you agree to the AWS re:Post Terms of Use

Can I use a single CloudFront web distribution to serve content from multiple origins using multiple behaviors?

2 minute read
0

I want to configure a single Amazon CloudFront web distribution to serve content from multiple origins using multiple behaviors.

Resolution

You can configure a single CloudFront web distribution to serve different types of requests from multiple origins. For example, your website might serve static content from an Amazon Simple Storage Service (Amazon S3) bucket and dynamic content from a load balancer. You can serve both types of content from a CloudFront web distribution.

Follow these steps to configure a CloudFront web distribution to serve static content from an S3 bucket and dynamic content from a load balancer:

  1. Open your web distribution from the CloudFront console.
  2. Choose the Origins tab.
  3. Create one origin for your S3 bucket, and another origin for your load balancer.
    Note: If you're using a custom origin server or an S3 website endpoint, you must enter the origin's domain name into the Origin Domain Name field.
  4. From your distribution, choose the Behaviors tab.
  5. Create a behavior that specifies a path pattern to route all static content requests to the S3 bucket. For example, you can set the "images/*.jpg" path pattern to route all requests for ".jpg" files in the images directory to the S3 bucket.
  6. Edit the Default (*) path pattern behavior and set its Origin as your load balancer.

Related information

Configure distributions

AWS OFFICIAL
AWS OFFICIALUpdated 4 months ago
1 Comment

Currently I am using a cloudfront distribution to serve my frontend. I am looking to use the same domain for backend too. For that I have added a behavior in cloudfront distribution. All the /api/* requests are mapped to go to an API gateway origin. However when I make the api call to /api/* path pattern, Im getting 404 Not found. The request is reaching cloudfront but not getting redirected to the api gateway.

I have verified for typos, origin path is empty and the api gateway url is functional. Am I missing something? I tried with both HTTP and REST APIs

replied 3 months ago