如何配置 Visual Studio Code 以解析 AWS Lambda 层的输入路径 (javascript) [英] How configure Visual Studio Code to resolve input paths for AWS Lambda Layers (javascript)

查看:32
本文介绍了如何配置 Visual Studio Code 以解析 AWS Lambda 层的输入路径 (javascript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 VS Code 来开发我的 AWS 托管的无服务器应用程序.该应用程序使用 Lambda.最近,我决定开始使用 Lambda 层来提取和重用公共代码.我遇到的问题是 AWS Lambda 需要以下 Lambda 层的导入:

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 common 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) {
        // ...
    }
}

尽管我同时拥有 lambda 和 lambda 层代码,VS Code 自然无法解析层文件的路径,因此 Intellisense 不起作用.

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.

我发现如果我将下一个 jsconfig.json 文件放在我的项目中的任何位置:

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

{
    "compilerOptions": {
        "target": "ES6",
        "module": "commonjs"
    },
    "exclude": [
        "node_modules",
        "**/node_modules/*"
    ]
}

require 语句不再显示为红色,并且允许一些基本的文本自动完成.但它并没有真正正确地显示带有参数的图层导出函数.

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

我不想创建解决方案,例如在开发期间使用自定义导入,然后在部署到 AWS 期间将它们替换为require("/opt/layer")"(或至少有一些自动化的东西).

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).

可以做什么?

推荐答案

最后,位于 lambda 文件夹中的下一个 jsconfig.json 文件对我有用(还需要重新启动 VS Code):

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

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es2015",
        "moduleResolution": "node",
        "baseUrl": ".",
        "paths": {
            "/opt/layer1": ["./layers/layer1"],
            "/opt/layer2": ["./layers/layer2"],
            "/opt/layer3": ["./layers/layer3"]
        }
    },
    "exclude": ["./layers/node_modules"]
}

这篇关于如何配置 Visual Studio Code 以解析 AWS Lambda 层的输入路径 (javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆