upash
upash copied to clipboard
Can this work in AWS lambda functions?
I can't seem to get the simple example to work in AWS lambda function. Appears to error on the upash.install line. Here is my function...
const upash = require('upash');
upash.install('argon2', require('@phc/argon2'));
exports.handler = function (event, context, callback) {
try {
console.log('===> body: ', event.body);
const hp = event.body.split('&');
const handle = hp[1].split('=')[1];
const pass = hp[0].split('=')[1];
console.log('===> handle: ', handle);
console.log('===> pass: ', pass);
(async () => {
const hashstr = await upash.hash(pass);
callback(null, {
statusCode: 200,
body: JSON.stringify({ hashstr })
});
})();
} catch (error) {
callback(null, {
statusCode: 500,
body: JSON.stringify(error)
});
}
};
If you move the upash.install inside the handler, the code will run up until it hits the upash.install line then the function errors (with a blank error message) at that point. So this is some kind of hard/can't-handle crash on that line when running in lambda functions
With the upash.installl line above/outside the function (like the code shows) you get a 'path' error...
Request from ::1: POST /gen-hash
Response with status 500 in 4 ms.
Error during invocation: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string
at assertPath (path.js:39:11)
at dirname (path.js:714:5)
at Function.r.getRoot (C:\Users\markd\Documents\code-projects\web\netlify\easy-message-bus-netlify-restapi\lambda\gen-hash.js:1:10807)
at r (C:\Users\markd\Documents\code-projects\web\netlify\easy-message-bus-netlify-restapi\lambda\gen-hash.js:1:10003)
at Object.117 (C:\Users\markd\Documents\code-projects\web\netlify\easy-message-bus-netlify-restapi\lambda\gen-hash.js:1:7659)
at t (C:\Users\markd\Documents\code-projects\web\netlify\easy-message-bus-netlify-restapi\lambda\gen-hash.js:1:220)
at Object.116 (C:\Users\markd\Documents\code-projects\web\netlify\easy-message-bus-netlify-restapi\lambda\gen-hash.js:1:3959)
at t (C:\Users\markd\Documents\code-projects\web\netlify\easy-message-bus-netlify-restapi\lambda\gen-hash.js:1:220)
at Object.135 (C:\Users\markd\Documents\code-projects\web\netlify\easy-message-bus-netlify-restapi\lambda\gen-hash.js:1:19423)
at t (C:\Users\markd\Documents\code-projects\web\netlify\easy-message-bus-netlify-restapi\lambda\gen-hash.js:1:220)
at C:\Users\markd\Documents\code-projects\web\netlify\easy-message-bus-netlify-restapi\lambda\gen-hash.js:1:1019
at Object.
at Module._compile (module.js:662:30)
at Object.Module._extensions..js (module.js:673:10)
at Module.load (module.js:575:32)
at tryModuleLoad (module.js:515:12)
I've looked through the install function and cant see a reason that it wouldnt work in a serverless environment. I can't seem to see the reference to upash in the stack trace? Do you have @phc/argon2
in your node_modules? I'm not to sure how lambda works with dependancies but it seems to have a problem loading a module.