getlift / lift

Expanding Serverless Framework beyond functions using the AWS CDK
MIT License
916 stars 113 forks source link

Use Lambda URL as CloudFront origin #368

Open kevincerro opened 11 months ago

kevincerro commented 11 months ago

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:

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 commented 11 months ago

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 commented 11 months ago

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

dnl4 commented 6 months ago

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

kevincerro commented 6 months ago

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