Jul 022020
 

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!

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.