简体   繁体   English

AWS Toolkit + VSCode 本地测试

[英]AWS Toolkit + VSCode local testing

I'm trying to figure out how to use AWS toolkit for vscode.我正在尝试弄清楚如何将 AWS 工具包用于 vscode。 I go to the AWS extension and click Create New SAM Application, point to project directory and it creates a hello world function.我转到 AWS 扩展并单击创建新 SAM 应用程序,指向项目目录并创建一个 hello world 函数。 Above it, it says Add Debug Configuration .在它上面,它说Add Debug Configuration I click that, choose nodejs 12.x and save the launch.json, but I don't get the run option.我点击它,选择 nodejs 12.x 并保存 launch.json,但我没有得到运行选项。 It still says Add Debug Configuration for some reason.出于某种原因,它仍然说Add Debug Configuration How can I run my lambda functions locally in the console?如何在控制台中本地运行我的 lambda 函数?
The launch.json file generates, but I can never run the code.生成了 launch.json 文件,但我永远无法运行代码。

在此处输入图片说明

launch.json启动文件

{
    "configurations": [
        {
            "type": "aws-sam",
            "request": "direct-invoke",
            "name": "new test:app.lambdaHandler (nodejs12.x)",
            "invokeTarget": {
                "target": "code",
                "projectRoot": "new test/hello-world",
                "lambdaHandler": "app.lambdaHandler"
            },
            "lambda": {
                "runtime": "nodejs12.x",
                "payload": {},
                "environmentVariables": {}
            }
        }
    ]
}

I also tried navigating to the hello-world directory in terminal and executing node app.js , but it doesn't return anything我还尝试导航到终端中的 hello-world 目录并执行node app.js ,但它没有返回任何内容

在此处输入图片说明

What am I doing wrong?我究竟做错了什么? I appreciate the help!我感谢您的帮助!

Make sure you have SAM CLI install in local, here are the instructions for installation https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html确保您在本地安装了 SAM CLI,这里是安装说明https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html

Then run the command sam local start-api .然后运行命令sam local start-api You should be able to access the api at http://127.0.0.1:3000/hello您应该可以访问http://127.0.0.1:3000/hello的 api

You can also do the same via vscode by selecting Run > Run without debugging (shortcut: ctrl + F5)您也可以通过 vscode 执行相同的操作,方法是选择 Run > Run without debugging(快捷键:ctrl + F5)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM