By using Lambda@Edge inside CloudFront I am not able to install packages thourgh npm as CloudFront does not allow layers:
According to AWS doc: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-at-edge-function-restrictions.html
Lambda Features
My approach is to validate jwt tokens using Viewer Request
Functions associated
There are multiple examples doing this, and they use common libraries such as:
import y from 'jsonwebtoken';
import z from 'jwk-to-pem';
But How should be referred if layers are not allowed? Using thus modules the application report errors:
Cannot find package 'jsonwebtoken' imported from /var/task/index.mjs"
On the other hand, creating a lambda with a cusotm layer with the following packages worked (But unable to use in aws-cloudfront):
{
"dependencies": {
"@types/jwk-to-pem": "^2.0.3",
"jsonwebtoken": "^9.0.2",
"jwk-to-pem": "^2.0.5",
"lodash": "^4.17.21"
}
}
Tried:
Expected to happen:
Actually result:
I was able to create the package without using a layer.
Solution: Deploy it as a zip file
Considerations: There is a maximum file size when using it in Lambda@Edge cloudfront.
https://docs.aws.amazon.com/lambda/latest/dg/nodejs-package.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With