最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - How configure Visual Studio Code to resolve input paths for AWS Lambda Layers (javascript) - Stack Overflow

programmeradmin6浏览0评论

I use VS Code for development of my AWS hosted serverless application. The app uses Lambdas. Recently, I've decided to start using Lambda Layers to extract and reuse mon code. The problem that I have is that AWS Lambda expects the following import of Lambda layer:

const layer = require("/opt/layer");

I would like to get Intellisense on layer exported functions:

module.exports = {
    f1(param1, param2) {
        // ...
    },

    f2(paramX, paramY, paramZ) {
        // ...
    }
}

And despite I possess both lambda and lambda layer code, VS Code naturally can't resolve the path to layer file and thus Intellisense doesn't work.

I've found that if I put the next jsconfig.json file anywhere in my project:

{
    "pilerOptions": {
        "target": "ES6",
        "module": "monjs"
    },
    "exclude": [
        "node_modules",
        "**/node_modules/*"
    ]
}

require statements stop to be shown in red and some basic text autopletion is allowed. But it doesn't really show layer exported functions with parameters correctly.

I would like not to create solutions like using custom imports during development then substitute them with "require("/opt/layer")" during deployment to AWS (or at least have some automated thing).

What can be done?

I use VS Code for development of my AWS hosted serverless application. The app uses Lambdas. Recently, I've decided to start using Lambda Layers to extract and reuse mon code. The problem that I have is that AWS Lambda expects the following import of Lambda layer:

const layer = require("/opt/layer");

I would like to get Intellisense on layer exported functions:

module.exports = {
    f1(param1, param2) {
        // ...
    },

    f2(paramX, paramY, paramZ) {
        // ...
    }
}

And despite I possess both lambda and lambda layer code, VS Code naturally can't resolve the path to layer file and thus Intellisense doesn't work.

I've found that if I put the next jsconfig.json file anywhere in my project:

{
    "pilerOptions": {
        "target": "ES6",
        "module": "monjs"
    },
    "exclude": [
        "node_modules",
        "**/node_modules/*"
    ]
}

require statements stop to be shown in red and some basic text autopletion is allowed. But it doesn't really show layer exported functions with parameters correctly.

I would like not to create solutions like using custom imports during development then substitute them with "require("/opt/layer")" during deployment to AWS (or at least have some automated thing).

What can be done?

Share Improve this question edited Nov 5, 2019 at 14:18 Arsenii Fomin asked Nov 5, 2019 at 11:20 Arsenii FominArsenii Fomin 3,3564 gold badges25 silver badges48 bronze badges 2
  • Might be helpful for you: stackoverflow./a/57553831/2692307 – Lukas Bach Commented Nov 5, 2019 at 14:20
  • @LukasBach Thank you for the suggestion but looks like it doesn't affect anything. I've noticed that even presence of "jsconfig.json" file without any content in it removes errors on "require"... some magic here. But Intellisense still doesn't work properly – Arsenii Fomin Commented Nov 5, 2019 at 14:33
Add a ment  | 

1 Answer 1

Reset to default 9

Finally, the next jsconfig.json file located in lambda folder worked for me (restarting VS Code also required):

{
    "pilerOptions": {
        "module": "monjs",
        "target": "es2015",
        "moduleResolution": "node",
        "baseUrl": ".",
        "paths": {
            "/opt/layer1": ["./layers/layer1"],
            "/opt/layer2": ["./layers/layer2"],
            "/opt/layer3": ["./layers/layer3"]
        }
    },
    "exclude": ["./layers/node_modules"]
}
发布评论

评论列表(0)

  1. 暂无评论