简体   繁体   中英

AWS Toolkit + VSCode local testing

I'm trying to figure out how to use AWS toolkit for vscode. I go to the AWS extension and click Create New SAM Application, point to project directory and it creates a hello world function. Above it, it says Add Debug Configuration . I click that, choose nodejs 12.x and save the launch.json, but I don't get the run option. It still says Add Debug Configuration for some reason. How can I run my lambda functions locally in the console?
The launch.json file generates, but I can never run the code.

在此处输入图片说明

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

在此处输入图片说明

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

Then run the command sam local start-api . You should be able to access the api at http://127.0.0.1:3000/hello

You can also do the same via vscode by selecting Run > Run without debugging (shortcut: ctrl + F5)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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