0

Right now I have a site hosted in S3 and delivery through Cloudfront and I have an application running on an EC2 instance. the problem is I need to serve the application using a folder in the domain associated with the CloudFront distribution, eg. example.com/app/

I know I can create a rule in the CloudFront distribution and process the request with a lambda function but seems like is not a good way to do it because I'll need to create a reliable proxy function and handle probably a lot of things

How proxy all request that comes to some path like "/app*" to an EC2 instance using Cloudfront?

  • 1
    Can you please edit your question so it says what you're trying to do, ideally with examples or a diagram, rather than just asking how to implement the solution you have in mind. I'm pretty sure CloudFront can send some paths to S3 and some to EC2 / ELB easily, without the use of lambda. – Tim Aug 22 '19 at 6:57
  • I have changed the question to be more explicit @Tim thank you – rkmax Aug 22 '19 at 13:26
0

You can use more than one origin with CloudFront, one of them will be S3 and the other the domain for your EC2 instance.

Then use CacheBehavior: PathPattern to proxy /app requests to your EC2 origin and DefaultCacheBehavior to proxy all the rest to S3 origin.

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-distribution-cachebehavior.html#cfn-cloudfront-distribution-cachebehavior-pathpattern

  • 1
    proxy /app requests should probably be either (simple) /app* or (more precise) both /app and /app/*. – Michael - sqlbot Aug 22 '19 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.