Currently I have CloudFront distribution that serves SPA (spa.myapp.com) from S3 bucket. I have also web server deployed in k8s on AWS.
Is it possible to forward all POST spa.myapp.com/* requests to my web server instead? What components / configuration I need to do this?
Is it possible to forward all spa.myapp.com/api/* requests to my web server instead (regardless of http method)? What components / configuration I need to do this?
Generally I want to serve SPA from CDN but also have few endpoints server side on same domain.
CodePudding user response:
- On your CloudFront Behavior for
*path you should allow all kind of methods:
You can have multiple behaviors, which can have different properties for caching. These behaviors are differentiated by their path pattern. They can also have a priority, the incoming requests are evaluated against higher precedence behaviors first. For example:
To answer your question, what you have to do is to create a different behavior for the /api/* path and apply a different configuration for this behavior. This has to have a higher precedence compared to the default behavior. Keep in mind that CloudFront caches GET, HEAD and OPTIONS requests only.



