Add EC2 Origin
Add EC2 Origin
In this step, you add the EC2 instance as a second origin and route /api* requests to it without caching.
- In the CloudFront console, open your distribution, select the Origins tab, then click Create origin.

- In Origin domain, enter the public DNS name of your EC2 instance. For Protocol, select HTTP only.

- Keep the other defaults and expand Additional settings.

- Set Keep-alive timeout to 60, then click Create origin.
Viewers still connect to CloudFront over HTTPS. Using HTTP between CloudFront and the origin avoids TLS overhead on that connection.

- The Origins list now shows the EC2 origin.

- Select the Behaviors tab and click Create behavior.

- Configure the behavior settings:
- Path pattern:
/api*
- Origin and origin groups: select the EC2 origin you created
- Viewer protocol policy: Redirect HTTP to HTTPS
- Allowed HTTP methods: GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE

- Under Cache key and origin requests, keep Cache policy and origin request policy (recommended) and set:
- Cache policy: CachingDisabled. CloudFront does not cache responses, which suits dynamic API content.
- Origin request policy: AllViewer. CloudFront forwards all headers, cookies, and query strings from the viewer request to the origin.

- Leave Function associations empty and click Create behavior.

- The
/api* behavior appears with precedence 0, above the Default (*) behavior. Wait until the distribution finishes deploying.
