Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Lambda URL as CloudFront origin #368

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kevincerro
Copy link

@kevincerro kevincerro commented Oct 22, 2023

Closes brefphp/bref#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
  • Ensure backwards compatibility
  • Ensure config is easy to understand
  • Implement multiple scenarios
    • No custom domain: Lambda Function URL
    • Website: CloudFront -> Lambda Function URL
    • 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 kevincerro changed the title Use lambda url as cloudfront origin if functionName is defined Use Lambda URL as cloudfront origin if functionName is defined Oct 22, 2023
@kevincerro kevincerro changed the title Use Lambda URL as cloudfront origin if functionName is defined Use Lambda URL as CloudFront origin if functionName is defined Oct 23, 2023
@kevincerro kevincerro changed the title Use Lambda URL as CloudFront origin if functionName is defined Use Lambda URL as CloudFront origin Oct 23, 2023
@kevincerro
Copy link
Author

kevincerro commented Oct 28, 2023

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 kevincerro marked this pull request as ready for review November 7, 2023 13:38
@kevincerro
Copy link
Author

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

@dnl4
Copy link

dnl4 commented Mar 28, 2024

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

@kevincerro
Copy link
Author

kevincerro commented Mar 28, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace API Gateway with CloudFront + Lambda Function URLs everywhere in Bref?
3 participants