I have an application that runs as AWS Lambda function using Cognito authentication. It all works fine but now I am attempting to optimise the bundle size to reduce cold start times.
The process of verifying and decoding the JWT involves:
- Fetch JWK from internal AWS endpoint
- Call jwkToPem from jwk-to-pem module
- Verify and decode JWT using jsonwebtoken module
When I look at the node_modules
in my archive, the largest packages are all related to the steps above:
elliptic 140kb
bn.js 108kb
jsonwebtoken 84kb
hash.js 80kb
asn1.js 72kb
hmac-drbg 36kb
jwk-to-pem 32kb
Total ~550kb
This is over half of node_modules
size and my application code is just 164kb un-minified, so as you can see the JWT decode has a substantial impact on overall bundle size.
Am wondering if there is a lighter weight alternative...
Thanks for any suggestions