Coder Social home page Coder Social logo

Comments (14)

mnapoli avatar mnapoli commented on July 22, 2024

This is actually the same issue with a custom domain name I believe.

One thing we could do is always drop the stage prefix (/dev) from the URL. That means it's easier to go from local development (e.g. Symfony routes) to online on API Gateway to production with a custom domain/Cloudfront: we use always the same routes.

But that also means that we are "hiding" the real URLs when on API Gateway. And if we use the router to generate URLs (e.g. links to other pages) then we generate wrong links… That sucks.

from bref.

nealio82 avatar nealio82 commented on July 22, 2024

@eddmann knows AWS architecture pretty well, any thoughts? Can the URI be mapped from one to the other programattically somehow on the AWS side?

from bref.

eddmann avatar eddmann commented on July 22, 2024

When you setup a custom domain within API gateway it internally sets up a CloudFront distro with the env. mapping you discuss. I would say the best bet is to have to CloudFront distro. one which API gateway manages and the other which is used to handle requests to static assets in S3 etc.
If you want to manipulate the request/response more in depth you could use Lambda@Edge which allows you to manipulate the client request/response and origin request/response.

from bref.

mnapoli avatar mnapoli commented on July 22, 2024

@eddmann yes, but the problem is when using CloudFront like this:

CloudFront -> API Gateway -> AWS Lambda

from bref.

eddmann avatar eddmann commented on July 22, 2024

@mnapoli Are you using CloudFront directly or via API Gateway?

from bref.

mnapoli avatar mnapoli commented on July 22, 2024

I am using it in front of API Gateway.

I use it to serve both assets from S3 and dynamic content from Lamdba in the same website/domain name.

I had an interesting answer on StackOverflow:

You could configure your CloudFront distribution to use a custom header that would be passed to the Lambda function. Then you could determine whether to use path or requestContext.path based on if that CloudFront-only header is present.

I guess that would work, but that's definitely not great to ask Bref users to do that for their projects… We could auto-create that header in Bref, but at the moment I haven't automated the creation of the CloudFront distribution.

from bref.

wysow avatar wysow commented on July 22, 2024

Sounds like a good "hack" which could be at least partially automated, and if we add some information in bref readme that should be fine for now, no?

from bref.

eddmann avatar eddmann commented on July 22, 2024

Ahh right. Yes you could add an additional header with CloudFront requests. Another option is to have two separate CloudFront distros. one which API Gateway manages (handling the desired prefix etc). and another which is used for static assets. Doing it this way however would require two separate domains which I'm assuming you are trying to get away from?

Another option that I haven't tried and am unsure on (due to Lambda sizes) is to store all assets within the Lambda along side the code. In this case you have a dedicated handler that gets run when static assets are requested. Performance for this would not be ideal on initial request but as you can tweak the Cache controls and API Gateway is going through CloudFront you will benefit from their caching platform.

from bref.

mnapoli avatar mnapoli commented on July 22, 2024

Doing it this way however would require two separate domains which I'm assuming you are trying to get away from?

Yes, I'm trying to make it possible to do what most PHP applications do, i.e. serve both PHP and assets under the same domain.

store all assets within the Lambda along side the code. In this case you have a dedicated handler that gets run when static assets are requested.

I wondered about this too. The first hit would be slow and that seems overkill to serve assets using PHP. And as you mention, it's too bad to have to upload the assets to the lambda, that doesn't seem ideal 🤔 But maybe for small application it could work… Anyway if I can make it work with CloudFront that's better IMO.

from bref.

wysow avatar wysow commented on July 22, 2024

Just my 2 cents, lambda zip file is limited to 50mb so all assets should be optimized, and they should be served by the node handler without ever hit the php handler, what do you think?

from bref.

nealio82 avatar nealio82 commented on July 22, 2024

Just my 2 cents, lambda zip file is limited to 50mb so all assets should be optimized, and they should be served by the node handler without ever hit the php handler, what do you think?

Hmm, wouldn't that cause a problem when the routing / management for assets is handled by the PHP framework?

from bref.

mnapoli avatar mnapoli commented on July 22, 2024

from bref.

nealio82 avatar nealio82 commented on July 22, 2024

Sure - maybe some configurable toggle to serve assets using node / PHP?

from bref.

mnapoli avatar mnapoli commented on July 22, 2024

Should be fixed in 0.3.

from bref.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.