JWT with Certificate + Severless


#1

Hey there!

I’m using JWT as authentication for my service. Everything is working fine when I use a secret, but now I need to use a certificate.

Following my folder structure I have the auth-token.js and then, in the same folder, I have certs/auth.pem. I tried a solution with fs:

import * as fs from ‘fs’

const cert = fs.readFileSync(’./certs/auth.pem’); AND const cert = fs.readFileSync(‘src/certs/auth.pem’);

Both break lambda in the following error:

module initialization error: Error
at Object.fs.readdirSync (fs.js:904:18)
at Object. (/var/task/handler.js:1228:16)
at webpack_require (/var/task/handler.js:20:30)
at Object.defineProperty.value (/var/task/handler.js:793:18)
at webpack_require (/var/task/handler.js:20:30)
at Object. (/var/task/handler.js:739:11)
at webpack_require (/var/task/handler.js:20:30)
at /var/task/handler.js:63:18
at Object. (/var/task/handler.js:66:10)
at Module._compile (module.js:652:30)

I even used path(‘src/certs/auth.pem’), but then I got /var/task/src/certs, used it but same error again.
When I read the folder src I get only my function handlers, nothing else (even other pieces of code that are working). I believe it’s some behavior on serverless/lambda, but this is something I’m not the most informed person.

Can anyone give me a tip? I’m uploading it to S3 now and using it from S3, just to make things walk, but can I solve it in an easier (fs file) way?