awslabs / cognito-at-edge

Serverless authentication solution to protect your website or Amplify application
Apache License 2.0
168 stars 54 forks source link

Lambda with cognito-at-edge too big for CloudFront #93

Open chbk opened 3 months ago

chbk commented 3 months ago

What happened:

Error: updating CloudFront Distribution: InvalidLambdaFunctionAssociation: The function code size is larger than the maximum allowed size for functions that are triggered by a CloudFront event: 1423536 Max allowed: 1048576

What did you expect to have happen:

No issues with cognito-at-edge version 1.5.0

How to reproduce this (as precisely and succinctly as possible):

package.json

{
  "name": "lambda",
  "dependencies": {
    "cognito-at-edge": "1.5.1"
  }
}

npm install

Then zip files and update lambda.

Environment:

cognito-at-edge version 1.5.1 node --version v20.11.0 npm --version 10.2.4

jeandek commented 3 months ago

Hi @chbk,

We use the CDK's NodejsFunction construct to deploy our test environments and we did not encounter any issues. Presumably esbuild is able to optimize and reduce the package size even with the default settings (no minify, etc.).

Unless you need the bug fix included in the latest version, I would recommend sticking to 1.5.0 for now. Long term, we would like to get rid of most of our external dependencies (axios and pica), but I can't commit to a specific timeline.

Cheers,