Using AWS Lambda with nodejs with Javascript.
Writing own library and use them as a layer.
Combine Lambda and Layer together.
Normally in Lambda, layer is found under /opt/
const shadowLib = require('/opt/shadow-lib');
But how to analyze, if layer is not found?
Try to get a list of all Files in /opt.
But how to get a list of all files from directory /opt? In AWS. In Lambda-function.
It works with nodejs12.
Try ist Lambda
const fs = require('fs');
const path = require('path');
function getFiles(srcpath) {
return fs.readdirSync(srcpath)
.map(file => path.join(srcpath, file))
.filter(path => fs.statSync(path));
}
exports.handler = async(event, context, callback) => {
const files = getFiles("/opt");
return files;
}
Et voilá – found my tipping error very quickly!
In AWS Lambda – searching for my Layer