Use Lambda URL as CloudFront origin
Closes https://github.com/brefphp/bref/issues/1625
This PR is a draft for using Lambda URL as CloudFront origin domain Please review and write your opinion about how we must handle logic about this
⚠️ Lambda URL limitation: using not urlEncoded queryParams will throw an exception
https://mywebsite.com/?SampleArg=Ky4gdyRYLiA0JSAMOWx9Iw==
X-Amzn-Errortype = InvalidQueryStringException
Pending:
- [ ] Protect Lambda URL using IAM
- [x] Ensure backwards compatibility
- [x] Ensure config is easy to understand
- Implement multiple scenarios
- [x] No custom domain: Lambda Function URL
- [x] Website: CloudFront -> Lambda Function URL
- [x] API: CloudFront -> Lambda Function URL
Configuration changes
Before
functions:
web:
handler: public/index.php
memorySize: 1769
timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
runtime: php-82-fpm
events:
- httpApi: '*'
constructs:
website:
type: server-side-website
domain: ${param:domain}
certificate: ${param:certificate}
assets:
'/assets/*': public/assets
After
functions:
web:
handler: public/index.php
memorySize: 1769
timeout: 60 # in seconds (Lambda URL has a timeout of 900 seconds)
runtime: php-82-fpm
url: true
constructs:
website:
type: server-side-website
domain: ${param:domain}
certificate: ${param:certificate}
originName: web
assets:
'/assets/*': public/assets
Example Symfony project using CloudFront + Lambda URL
https://docs.block2code.com/components
Screenshots
Uploaded some changes @mnapoli
I didn't managed to pass ts-lint checks on utils/GetWebLambdaFunctions.ts after some hours, sorry 😢 .
( e.httpApi || e.http || e.alb not valid)
(Maybe something is wrong with AWS function events typescript definition)
@mnapoli Can you review last changes? Thanks! 👍🏻
Hello @kevincerro, there is any update on this? This change will for sure reduce costs.
Hello @kevincerro, there is any update on this? This change will for sure reduce costs.
Hello, no changes since last comment.
I've a forked version of lift package with this PR changes => npm install --require-dev @kevinc123/serverless-lift
Working in my prod env for some months. Will be amazing if you can try them also