Comments (14)
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.
@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.
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.
@eddmann yes, but the problem is when using CloudFront like this:
CloudFront -> API Gateway -> AWS Lambda
from bref.
@mnapoli Are you using CloudFront directly or via API Gateway?
from bref.
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.
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.
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.
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.
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.
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.
from bref.
Sure - maybe some configurable toggle to serve assets using node / PHP?
from bref.
Should be fixed in 0.3.
from bref.
Related Issues (20)
- Feedback for “Cron tasks on AWS Lambda” HOT 1
- Handle "Response too big" in Console functions HOT 2
- PlanetScale removed the Hobby tier
- Long running CLI commands repeat every 2 minutes HOT 1
- Troubleshooting Bref Docker Deployment with Octane Handler
- Symfony CLI DATABASE_URL Not Found HOT 1
- Can I fire putJobSuccessResult event from AWS Lambda which is developed with Bref? HOT 1
- Feedback for “Custom domain names” HOT 1
- I am getting this issue :-
- OPENSSL_3.3.0' not found (required by /opt/lib/libssl.so.3) HOT 10
- Stopping 1.x maintenance
- Feedback for “Serverless Laravel - Getting started” HOT 3
- NOTICE since upgrading to v2 HOT 1
- Brefv2 500 Errors Not In Logs HOT 5
- PHP ext-intl is required on layer 8.3 HOT 1
- CURL SSL_ERROR_SYSCALL calling another Lambda HOT 7
- Env always return null after update packages to bref 2 version
- max_execution_time not working HOT 3
- Laravel 11, PHP 8.3 mysql driver not enabled, also can't use postgress
- Bref Serverless v4 HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bref.