lift icon indicating copy to clipboard operation
lift copied to clipboard

Use Lambda URL as CloudFront origin

Open kevincerro opened this issue 2 years ago • 6 comments

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

Captura de pantalla 2023-10-23 a las 2 09 41 Captura de pantalla 2023-10-23 a las 2 10 56 Captura de pantalla 2023-10-23 a las 2 14 38

kevincerro avatar Oct 22 '23 23:10 kevincerro

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) Captura de pantalla 2023-10-28 a las 21 26 30

kevincerro avatar Oct 28 '23 19:10 kevincerro

@mnapoli Can you review last changes? Thanks! 👍🏻

kevincerro avatar Nov 08 '23 11:11 kevincerro

Hello @kevincerro, there is any update on this? This change will for sure reduce costs.

dnl4 avatar Mar 28 '24 20:03 dnl4

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

kevincerro avatar Mar 28 '24 20:03 kevincerro