aws-toolkit-vscode icon indicating copy to clipboard operation
aws-toolkit-vscode copied to clipboard

lambda code not in root (CDK typescript project)

Open sambarfoot opened this issue 4 years ago • 23 comments

Desktop:

  • OS: Mac
  • VS Code version: 1.52.1
  • AWS Toolkit extension version: 1.18.0

When using cdk, how do you setup a lambda debug where the lambda is not in the root?

{
  "configurations": [
    {
      "type": "aws-sam",
      "request": "direct-invoke",
      "name": "lambda debug",
      "invokeTarget": {
        "target": "code",
        "projectRoot": "",
        "lambdaHandler": "lib/lambdas/helloworld/hello.handler"
      },
      "lambda": {
        "runtime": "nodejs10.x",
        "payload": {},
        "environmentVariables": {}
      }
    }
  ]
}

Debugger attached. 2021-01-30T14:01:55.990Z undefined ERROR Uncaught Exception {"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'hello'","stack":["Runtime.ImportModuleError: Error: Cannot find module 'hello'"," at _loadUserApp (/var/runtime/UserFunction.js:100:13)"," at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)"," at Object. (/var/runtime/index.js:45:30)"," at Module._compile (internal/modules/cjs/loader.js:775:14)"," at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)"," at Module.load (internal/modules/cjs/loader.js:653:32)"," at tryModuleLoad (internal/modules/cjs/loader.js:593:12)"," at Function.Module._load (internal/modules/cjs/loader.js:585:3)"," at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)"," at startup (internal/bootstrap/node.js:283:19)"]}

sambarfoot avatar Jan 30 '21 14:01 sambarfoot

Are all of these conditions true? :

1.lib/ is a direct child of the current VSCode workspace 2. lib/lambdas/helloworld/hello.js exists 3. handler() is an exported function in hello.js (e.g. exports.handler = async (event, context) => { ... })

Generally projectRoot points to a directory containing package.json and lambdaHandler is relative to that. E.g. if lib/lambdas/helloworld contains package.json :

        "projectRoot": "lib/lambdas/helloworld",
        "lambdaHandler": "hello.handler"

justinmk3 avatar Feb 01 '21 14:02 justinmk3

Hi Justin, thanks for the prompt response. Here is a screenshot of my directory. image

below is the hello.js file, generated from the ts.

Object.defineProperty(exports, "__esModule", { value: true });
exports.handler = void 0;
const handler = async (event) => {
    console.log("request:", JSON.stringify(event, undefined, 2));
    return {
        statusCode: 200,
        headers: { "Content-Type": "text/plain" },
        body: `Hello, You've hit ${event.path}\n`
    };
};
exports.handler = handler;

sambarfoot avatar Feb 01 '21 14:02 sambarfoot

Based on your screenshot, I think you need:

"lambdaHandler": "lib/lambdas/hello/hello.handler"

instead of

"lambdaHandler": "lib/lambdas/helloworld/hello.handler"

justinmk3 avatar Feb 01 '21 16:02 justinmk3

apologies, helloworld must have been typing error in the ticket.

{
  "configurations": [
    {
      "type": "aws-sam",
      "request": "direct-invoke",
      "name": "lambda debug",
      "invokeTarget": {
        "target": "code",
        "projectRoot": "",
        "lambdaHandler": "lib/lambdas/hello/hello.handler"
      },
      "lambda": {
        "runtime": "nodejs10.x",
        "payload": {},
        "environmentVariables": {}
      }
    }
  ]
}

output

Debugger attached.
2021-02-01T16:55:06.792Z	undefined	ERROR	Uncaught Exception	{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'hello'","stack":["Runtime.ImportModuleError: Error: Cannot find module 'hello'","    at _loadUserApp (/var/runtime/UserFunction.js:100:13)","    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)","    at Object.<anonymous> (/var/runtime/index.js:45:30)","    at Module._compile (internal/modules/cjs/loader.js:775:14)","    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)","    at Module.load (internal/modules/cjs/loader.js:653:32)","    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)","    at Function.Module._load (internal/modules/cjs/loader.js:585:3)","    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)","    at startup (internal/bootstrap/node.js:283:19)"]}
time="2021-02-01T16:55:06.799" level=panic msg="ReplyStream not available"
2021/02/01 16:55:06 http: panic serving 127.0.0.1:52946: &{0xc00001e0e0 map[] 2021-02-01 16:55:06.799971389 +0000 UTC m=+3.795559707 panic <nil> ReplyStream not available <nil> <nil> }
goroutine 14 [running]:
net/http.(*conn).serve.func1(0xc000082c80)
	/usr/local/go/src/net/http/server.go:1800 +0x139
panic(0x866640, 0xc00001e310)
	/usr/local/go/src/runtime/panic.go:975 +0x3e3
github.com/sirupsen/logrus.Entry.log(0xc00001e0e0, 0xc000069500, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/go/pkg/mod/github.com/sirupsen/[email protected]/entry.go:259 +0x335
github.com/sirupsen/logrus.(*Entry).Log(0xc00001e230, 0xc000000000, 0xc00014d588, 0x1, 0x1)
	/go/pkg/mod/github.com/sirupsen/[email protected]/entry.go:287 +0xeb
github.com/sirupsen/logrus.(*Logger).Log(0xc00001e0e0, 0xc000000000, 0xc00014d588, 0x1, 0x1)
	/go/pkg/mod/github.com/sirupsen/[email protected]/logger.go:193 +0x7d
github.com/sirupsen/logrus.(*Logger).Panic(...)
	/go/pkg/mod/github.com/sirupsen/[email protected]/logger.go:234
github.com/sirupsen/logrus.Panic(...)
	/go/pkg/mod/github.com/sirupsen/[email protected]/exported.go:129
go.amzn.com/lambda/rapi/rendering.RenderInteropError(0x9097c0, 0xc0000d02a0, 0xc0000b6c00, 0x902b60, 0xc00002f110)
	/LambdaRuntimeLocal/lambda/rapi/rendering/rendering.go:292 +0x9a
go.amzn.com/lambda/rapi/handler.(*initErrorHandler).ServeHTTP(0xc00010c0a0, 0x9097c0, 0xc0000d02a0, 0xc0000b6c00)
	/LambdaRuntimeLocal/lambda/rapi/handler/initerror.go:52 +0x519
net/http.HandlerFunc.ServeHTTP(0xc000102380, 0x9097c0, 0xc0000d02a0, 0xc0000b6c00)
	/usr/local/go/src/net/http/server.go:2041 +0x44
github.com/go-chi/chi.(*Mux).routeHTTP(0xc000100120, 0x9097c0, 0xc0000d02a0, 0xc0000b6c00)
	/go/pkg/mod/github.com/go-chi/[email protected]+incompatible/mux.go:431 +0x278
net/http.HandlerFunc.ServeHTTP(0xc00010c030, 0x9097c0, 0xc0000d02a0, 0xc0000b6c00)
	/usr/local/go/src/net/http/server.go:2041 +0x44
go.amzn.com/lambda/rapi/middleware.RuntimeReleaseMiddleware.func1.1(0x9097c0, 0xc0000d02a0, 0xc0000b6c00)
	/LambdaRuntimeLocal/lambda/rapi/middleware/middleware.go:100 +0xea
net/http.HandlerFunc.ServeHTTP(0xc000102180, 0x9097c0, 0xc0000d02a0, 0xc0000b6c00)
	/usr/local/go/src/net/http/server.go:2041 +0x44
go.amzn.com/lambda/rapi/middleware.AccessLogMiddleware.func1.1(0x9097c0, 0xc0000d02a0, 0xc0000b6c00)
	/LambdaRuntimeLocal/lambda/rapi/middleware/middleware.go:77 +0x170
net/http.HandlerFunc.ServeHTTP(0xc0001021a0, 0x9097c0, 0xc0000d02a0, 0xc0000b6c00)
	/usr/local/go/src/net/http/server.go:2041 +0x44
go.amzn.com/lambda/rapi/middleware.AppCtxMiddleware.func1.1(0x9097c0, 0xc0000d02a0, 0xc0000b6b00)
	/LambdaRuntimeLocal/lambda/rapi/middleware/middleware.go:66 +0x77
net/http.HandlerFunc.ServeHTTP(0xc00010a2d0, 0x9097c0, 0xc0000d02a0, 0xc0000b6b00)
	/usr/local/go/src/net/http/server.go:2041 +0x44
github.com/go-chi/chi.(*Mux).ServeHTTP(0xc000100120, 0x9097c0, 0xc0000d02a0, 0xc0000b6b00)
	/go/pkg/mod/github.com/go-chi/[email protected]+incompatible/mux.go:70 +0x513
github.com/go-chi/chi.(*Mux).Mount.func1(0x9097c0, 0xc0000d02a0, 0xc0000b6b00)
	/go/pkg/mod/github.com/go-chi/[email protected]+incompatible/mux.go:298 +0x118
net/http.HandlerFunc.ServeHTTP(0xc0001023e0, 0x9097c0, 0xc0000d02a0, 0xc0000b6b00)
	/usr/local/go/src/net/http/server.go:2041 +0x44
github.com/go-chi/chi.(*Mux).routeHTTP(0xc0001000c0, 0x9097c0, 0xc0000d02a0, 0xc0000b6b00)
	/go/pkg/mod/github.com/go-chi/[email protected]+incompatible/mux.go:431 +0x278
net/http.HandlerFunc.ServeHTTP(0xc00010c0c0, 0x9097c0, 0xc0000d02a0, 0xc0000b6b00)
	/usr/local/go/src/net/http/server.go:2041 +0x44
github.com/go-chi/chi.(*Mux).ServeHTTP(0xc0001000c0, 0x9097c0, 0xc0000d02a0, 0xc0000b6900)
	/go/pkg/mod/github.com/go-chi/[email protected]+incompatible/mux.go:86 +0x2b2
net/http.serverHandler.ServeHTTP(0xc00011a000, 0x9097c0, 0xc0000d02a0, 0xc0000b6900)
	/usr/local/go/src/net/http/server.go:2836 +0xa3
net/http.(*conn).serve(0xc000082c80, 0x90a800, 0xc0000806c0)
	/usr/local/go/src/net/http/server.go:1924 +0x86c
created by net/http.(*Server).Serve
	/usr/local/go/src/net/http/server.go:2962 +0x35c
2021-02-01T16:55:06.805Z	undefined	ERROR	Uncaught Exception	{"errorType":"Error","errorMessage":"socket hang up","code":"ECONNRESET","stack":["Error: socket hang up","    at createHangUpError (_http_client.js:332:15)","    at Socket.socketOnEnd (_http_client.js:435:23)","    at Socket.emit (events.js:203:15)","    at endReadableNT (_stream_readable.js:1145:12)","    at process._tickCallback (internal/process/next_tick.js:63:19)"]}
Waiting for the debugger to disconnect...
time="2021-02-01T16:55:06.838" level=error msg="Init failed" InvokeID= error="Runtime exited with error: exit status 129"
time="2021-02-01T16:55:06.839" level=error msg="INIT DONE failed: Runtime.ExitError"

sambarfoot avatar Feb 01 '21 16:02 sambarfoot

Can you check (or share) the logs further up to see if it's failing at the sam build step or sam local invoke ?

Before trying to debug, you can narrow down the issue by trying to sam build ... and sam local invoke the project, in a terminal without VSCode or the AWS Toolkit. If that doesn't work, that narrows the problem significantly.

If you can share the full logs (after ensuring no private information is in it, if any), I can make a more concrete suggestion.

justinmk3 avatar Feb 02 '21 00:02 justinmk3

this is build logs

Preparing to debug locally: Lambda "lib/lambdas/hello/hello.handler"
Building SAM application...
Running command: (not started) [/usr/local/bin/sam build --build-dir /tmp/aws-toolkit-vscode/vsctk4iy1xo/output --template /Users/sambarfoot/Documents/<hidden folder>/app/debug_locally/app___vsctk___template.yaml --base-dir /Users/sambarfoot/Documents/<hidden folder>/app/debug_locally]
Building codeuri: /Users/sambarfoot/Documents/<hidden folder>/app/debug_locally runtime: nodejs10.x metadata: {} functions: ['awsToolkitSamLocalResource']
Running NodejsNpmBuilder:NpmPack
Running NodejsNpmBuilder:CopyNpmrc
Running NodejsNpmBuilder:CopySource
Running NodejsNpmBuilder:NpmInstall
Running NodejsNpmBuilder:CleanUpNpmrc

Build Succeeded

Built Artifacts  : private/tmp/aws-toolkit-vscode/vsctk4iy1xo/output
Built Template   : private/tmp/aws-toolkit-vscode/vsctk4iy1xo/output/template.yaml

Commands you can use next
=========================
[*] Invoke Function: sam local invoke -t private/tmp/aws-toolkit-vscode/vsctk4iy1xo/output/template.yaml
[*] Deploy: sam deploy --guided --template-file private/tmp/aws-toolkit-vscode/vsctk4iy1xo/output/template.yaml
    
Build complete.
Starting SAM application locally
Running: (not started) [/usr/local/bin/sam local invoke awsToolkitSamLocalResource --template /tmp/aws-toolkit-vscode/vsctk4iy1xo/output/template.yaml --event /tmp/aws-toolkit-vscode/vsctk4iy1xo/event.json --env-vars /tmp/aws-toolkit-vscode/vsctk4iy1xo/env-vars.json -d 5858]
Invoking lib/lambdas/hello/hello.handler (nodejs10.x)
Skip pulling image and use local one: amazon/aws-sam-cli-emulation-image-nodejs10.x:rapid-1.16.0.

Mounting /tmp/aws-toolkit-vscode/vsctk4iy1xo/output/awsToolkitSamLocalResource as /var/task:ro,delegated inside runtime container
START RequestId: 5317e65d-e0d2-47a5-8d7a-d3cc6355bd2c Version: $LATEST
Debugger listening on ws://0.0.0.0:5858/eb0e2309-8f1f-4b1f-8753-8e67e8fd74a0
For help, see: https://nodejs.org/en/docs/inspector
Waiting for SAM application to start...
Attaching debugger to SAM application...
Debugger attached.
Debugger attached
2021-02-02T08:23:51.888Z	undefined	ERROR	Uncaught Exception	{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'hello'","stack":["Runtime.ImportModuleError: Error: Cannot find module 'hello'","    at _loadUserApp (/var/runtime/UserFunction.js:100:13)","    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)","    at Object.<anonymous> (/var/runtime/index.js:45:30)","    at Module._compile (internal/modules/cjs/loader.js:775:14)","    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)","    at Module.load (internal/modules/cjs/loader.js:653:32)","    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)","    at Function.Module._load (internal/modules/cjs/loader.js:585:3)","    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)","    at startup (internal/bootstrap/node.js:283:19)"]}
time="2021-02-02T08:23:51.896" level=panic msg="ReplyStream not available"
2021/02/02 08:23:51 http: panic serving 127.0.0.1:48870: &{0xc00001e0e0 map[] 2021-02-02 08:23:51.896581865 +0000 UTC m=+6.201728365 panic <nil> ReplyStream not available <nil> <nil> }
goroutine 28 [running]:
net/http.(*conn).serve.func1(0xc0001175e0)
	/usr/local/go/src/net/http/server.go:1800 +0x139
panic(0x866640, 0xc0001560e0)
	/usr/local/go/src/runtime/panic.go:975 +0x3e3
github.com/sirupsen/logrus.Entry.log(0xc00001e0e0, 0xc000108bd0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/go/pkg/mod/github.com/sirupsen/[email protected]/entry.go:259 +0x335
github.com/sirupsen/logrus.(*Entry).Log(0xc000156000, 0xc000000000, 0xc00014f588, 0x1, 0x1)
	/go/pkg/mod/github.com/sirupsen/[email protected]/entry.go:287 +0xeb
github.com/sirupsen/logrus.(*Logger).Log(0xc00001e0e0, 0xc000000000, 0xc00014f588, 0x1, 0x1)
	/go/pkg/mod/github.com/sirupsen/[email protected]/logger.go:193 +0x7d
github.com/sirupsen/logrus.(*Logger).Panic(...)
	/go/pkg/mod/github.com/sirupsen/[email protected]/logger.go:234
github.com/sirupsen/logrus.Panic(...)
	/go/pkg/mod/github.com/sirupsen/[email protected]/exported.go:129
go.amzn.com/lambda/rapi/rendering.RenderInteropError(0x9097c0, 0xc00011a2a0, 0xc00012eb00, 0x902b60, 0xc00010a390)
	/LambdaRuntimeLocal/lambda/rapi/rendering/rendering.go:292 +0x9a
go.amzn.com/lambda/rapi/handler.(*initErrorHandler).ServeHTTP(0xc00010a0a0, 0x9097c0, 0xc00011a2a0, 0xc00012eb00)
	/LambdaRuntimeLocal/lambda/rapi/handler/initerror.go:52 +0x519
net/http.HandlerFunc.ServeHTTP(0xc000100380, 0x9097c0, 0xc00011a2a0, 0xc00012eb00)
	/usr/local/go/src/net/http/server.go:2041 +0x44
github.com/go-chi/chi.(*Mux).routeHTTP(0xc0001140c0, 0x9097c0, 0xc00011a2a0, 0xc00012eb00)
	/go/pkg/mod/github.com/go-chi/[email protected]+incompatible/mux.go:431 +0x278
net/http.HandlerFunc.ServeHTTP(0xc00010a030, 0x9097c0, 0xc00011a2a0, 0xc00012eb00)
	/usr/local/go/src/net/http/server.go:2041 +0x44
go.amzn.com/lambda/rapi/middleware.RuntimeReleaseMiddleware.func1.1(0x9097c0, 0xc00011a2a0, 0xc00012eb00)
	/LambdaRuntimeLocal/lambda/rapi/middleware/middleware.go:100 +0xea
net/http.HandlerFunc.ServeHTTP(0xc000100180, 0x9097c0, 0xc00011a2a0, 0xc00012eb00)
	/usr/local/go/src/net/http/server.go:2041 +0x44
go.amzn.com/lambda/rapi/middleware.AccessLogMiddleware.func1.1(0x9097c0, 0xc00011a2a0, 0xc00012eb00)
	/LambdaRuntimeLocal/lambda/rapi/middleware/middleware.go:77 +0x170
net/http.HandlerFunc.ServeHTTP(0xc0001001a0, 0x9097c0, 0xc00011a2a0, 0xc00012eb00)
	/usr/local/go/src/net/http/server.go:2041 +0x44
go.amzn.com/lambda/rapi/middleware.AppCtxMiddleware.func1.1(0x9097c0, 0xc00011a2a0, 0xc00012ea00)
	/LambdaRuntimeLocal/lambda/rapi/middleware/middleware.go:66 +0x77
net/http.HandlerFunc.ServeHTTP(0xc0001082d0, 0x9097c0, 0xc00011a2a0, 0xc00012ea00)
	/usr/local/go/src/net/http/server.go:2041 +0x44
github.com/go-chi/chi.(*Mux).ServeHTTP(0xc0001140c0, 0x9097c0, 0xc00011a2a0, 0xc00012ea00)
	/go/pkg/mod/github.com/go-chi/[email protected]+incompatible/mux.go:70 +0x513
github.com/go-chi/chi.(*Mux).Mount.func1(0x9097c0, 0xc00011a2a0, 0xc00012ea00)
	/go/pkg/mod/github.com/go-chi/[email protected]+incompatible/mux.go:298 +0x118
net/http.HandlerFunc.ServeHTTP(0xc0001003e0, 0x9097c0, 0xc00011a2a0, 0xc00012ea00)
	/usr/local/go/src/net/http/server.go:2041 +0x44
github.com/go-chi/chi.(*Mux).routeHTTP(0xc000114060, 0x9097c0, 0xc00011a2a0, 0xc00012ea00)
	/go/pkg/mod/github.com/go-chi/[email protected]+incompatible/mux.go:431 +0x278
net/http.HandlerFunc.ServeHTTP(0xc00010a0c0, 0x9097c0, 0xc00011a2a0, 0xc00012ea00)
	/usr/local/go/src/net/http/server.go:2041 +0x44
github.com/go-chi/chi.(*Mux).ServeHTTP(0xc000114060, 0x9097c0, 0xc00011a2a0, 0xc00012e800)
	/go/pkg/mod/github.com/go-chi/[email protected]+incompatible/mux.go:86 +0x2b2
net/http.serverHandler.ServeHTTP(0xc00011a000, 0x9097c0, 0xc00011a2a0, 0xc00012e800)
	/usr/local/go/src/net/http/server.go:2836 +0xa3
net/http.(*conn).serve(0xc0001175e0, 0x90a800, 0xc00010ffc0)
	/usr/local/go/src/net/http/server.go:1924 +0x86c
created by net/http.(*Server).Serve
	/usr/local/go/src/net/http/server.go:2962 +0x35c
2021-02-02T08:23:51.925Z	undefined	ERROR	Uncaught Exception	{"errorType":"Error","errorMessage":"socket hang up","code":"ECONNRESET","stack":["Error: socket hang up","    at createHangUpError (_http_client.js:332:15)","    at Socket.socketOnEnd (_http_client.js:435:23)","    at Socket.emit (events.js:203:15)","    at endReadableNT (_stream_readable.js:1145:12)","    at process._tickCallback (internal/process/next_tick.js:63:19)"]}
Waiting for the debugger to disconnect...
time="2021-02-02T08:23:52.003" level=error msg="Init failed" InvokeID= error="Runtime exited with error: exit status 129"
time="2021-02-02T08:23:52.004" level=error msg="INIT DONE failed: Runtime.ExitError"
Command stopped: "sam local invoke"

sambarfoot avatar Feb 02 '21 08:02 sambarfoot

How did you create the launch config? Did you click Add Debug Configuration from hello.js ?

I can reproduce the symptom by misconfiguring lambdaHandler, so I think we're close to a solution. We just need to satisfy these requirements:

  1. projectRoot points to the folder containing package.json
    • for troubleshooting, try setting this to an absolute path
  2. lambdaHandler points to the exported Lambda function relative to projectRoot.

If you can send a minimal zip that reproduces the issue I can play around with it.

Just a guess, but since hello.js has the same name as its parent folder, maybe JS/TS expects this:

"lambdaHandler": "lib/lambdas/hello.handler"

instead of

"lambdaHandler": "lib/lambdas/hello/hello.handler"

justinmk3 avatar Feb 02 '21 16:02 justinmk3

I used the add debug configuration button from within the .js image

I tried trying the changing the path like you said but still the same issue

below is a copy of the minimal code

debug_locally.zip

thank you

sambarfoot avatar Feb 02 '21 18:02 sambarfoot

  • For reference: latest sam 1.17 release doesn't change this behavior so it's not related to https://github.com/aws/aws-sam-cli/issues/2573
  • I noticed that package.json does not specify aws-sdk in dependencies.

The main problem is likely that it's a typescript project, and Toolkit SAM debug feature does not yet have explicit understanding of typescript.

In the attached sample project, the .js files aren't copied to the output directory, so they of course can't be debugged in the Docker container. This can probably be fixed by changing the package.json file to treat the project as a javascript project instead of typescript.... but that is not ideal.

Related: https://github.com/aws/aws-toolkit-vscode/issues/1453

justinmk3 avatar Feb 05 '21 01:02 justinmk3

Are we likely to see support for typescript soon?

Do you think if I change the output of the build, it might work? Using the following launch.json the code runs.

{
  "configurations": [
    {
      "type": "aws-sam",
      "request": "direct-invoke",
      "name": "hello.handler (nodejs10.x)",
      "invokeTarget": {
        "target": "code",
        "projectRoot": "lib/lambdas/hello/",
        "lambdaHandler": "hello.handler"
      },
      "lambda": {
        "runtime": "nodejs10.x",
        "payload": {},
        "environmentVariables": {}
      }
    }
  ]
}
2021-02-15 21:46:56 [ERROR]: 2021-02-15T21:46:56.022Z	24a124a8-c68c-4be7-8330-bf4a764354b4	INFO	request: {}
2021-02-15 21:46:56 [ERROR]: END RequestId: 24a124a8-c68c-4be7-8330-bf4a764354b4
REPORT RequestId: 24a124a8-c68c-4be7-8330-bf4a764354b4	Init Duration: 1.08 ms	Duration: 4702.62 ms	Billed Duration: 4800 ms	Memory Size: 128 MB	Max Memory Used: 128 MB	
2021-02-15 21:46:56 [INFO]: {"statusCode":200,"headers":{"Content-Type":"text/plain"},"body":"Hello, You've hit undefined\n"}

sambarfoot avatar Feb 15 '21 21:02 sambarfoot

Are we likely to see support for typescript soon?

We are considering it, timeline is uncertain.

Do you think if I change the output of the build, it might work?

As long as sam sees javascript and deploys it to the Docker container, it should work.

Using the following launch.json the code runs.

Great! We may need to revisit projectRoot, seems that our codelens did not generate the correct launch config for this case.

justinmk3 avatar Feb 15 '21 22:02 justinmk3

SAM CLI is working on CDK support, which may also help here. https://github.com/aws/aws-sam-cli/releases/tag/sam-cli-beta-cdk

justinmk3 avatar May 05 '21 17:05 justinmk3

Are we likely to see support for typescript soon?

@sambarfoot We are working on typescript support in the feature/typescript-sam branch. If you can try the prerelease build, we'd love your feedback:

  1. Download and extract buildArtifacts.zip
  2. From the VSCode command list (ctrl-shift-p or cmd-shift-p) run Extensions: Install from VSIX... to install the *.vsix file.
  3. Reload VSCode and verify that the Toolkit has the new version 1.26 (not the older version 1.25).

justinmk3 avatar May 27 '21 17:05 justinmk3

@justinmk3 thank you for the update I will try this

sambarfoot avatar Jun 02 '21 14:06 sambarfoot

so I tried the debugger and get this error image

sambarfoot avatar Jun 09 '21 17:06 sambarfoot

installing typescript globally seems to fix the problem, shame you can't use the project one. npm install -g typescript

Update: it would seem that none of the packages are available as ive run another test and the import is empty

sambarfoot avatar Jun 09 '21 17:06 sambarfoot

installing typescript globally seems to fix the problem, shame you can't use the project one.

Agreed, Toolkit can look for node_modules/.bin/tsc via vscode.workspace.findFiles().

Update: it would seem that none of the packages are available as ive run another test and the import is empty

Ok, we need to take a closer look at this use case specifically (CDK typescript project).

justinmk3 avatar Jun 14 '21 22:06 justinmk3

@justinmk3 what do you need from me?

sambarfoot avatar Jun 18 '21 07:06 sambarfoot

installing typescript globally seems to fix the problem, shame you can't use the project one.

AWS Toolkit no longer requires global tsc, it will try to find the one in your local node_modules.

SAM CLI is working on CDK support, which may also help here. https://github.com/aws/aws-sam-cli/releases/tag/sam-cli-beta-cdk

This is now launched! https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-cdk.html

justinmk3 avatar Jan 07 '22 19:01 justinmk3

I have a similar problem to the above issue (the one with the picture where it can't find tsc but in my case it can't find tsconfig.json).

I have my package.json, node_modules and tsconfig.json files in my src/ directory. When I run the debugger in vscode I get the error message:

2022-09-13 17:50:57 [INFO]: Preparing to debug locally: Lambda "cleanupLeftoverTestAssets.handler"
2022-09-13 17:50:57 [INFO]: Building SAM application...
2022-09-13 17:50:57 [INFO]: Command: (not started) [/usr/local/bin/sam build --build-dir /tmp/aws-toolkit-vscode/vsctkTZ4wxw/output --template /tmp/aws-toolkit-vscode/vsctkTZ4wxw/app___vsctk___template.yaml --base-dir /Users/josh/git/lambda-jobs/src]
2022-09-13 17:51:01 [INFO]: Build complete.
2022-09-13 17:51:01 [ERROR]: SamLaunchRequestError: Failed to run launch configuration
	 -> Error: tsconfig.json or *.ts not found in: "/tmp/aws-toolkit-vscode/vsctkTZ4wxw/output/*"

When I look at the output directory it has this:

ls /tmp/aws-toolkit-vscode/vsctkcBXB7s/output/*
/tmp/aws-toolkit-vscode/vsctkcBXB7s/output/template.yaml

/tmp/aws-toolkit-vscode/vsctkcBXB7s/output/src:
dist              node_modules      package-lock.json package.json

Here is tsconfig.json (in the src/ directory)

{
  "compilerOptions": {
    "lib": ["es2020"],
    "module": "commonjs",
    "moduleResolution": "node",
    "target": "es2020",
    "sourceMap": true,
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,

    "outDir": "dist",
    "rootDir": "."
  },
  "include": [
    "./"
  ]
}

Here is my launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "aws-sam",
      "request": "direct-invoke",
      "name": "Invoke Cleanup Test Assets Lambda",
      "invokeTarget": {
        "target": "code",
        "projectRoot": "${workspaceFolder}/src",
        "lambdaHandler": "cleanupLeftoverTestAssets.handler"
      },
      "lambda": {
        "runtime": "nodejs14.x",
        "payload": {},
        "environmentVariables": {}
      }
    }
  ]
}

Any help or guidance would be appreciated.

josh803316 avatar Sep 14 '22 01:09 josh803316

@josh803316 I have created https://github.com/aws/aws-toolkit-vscode/issues/2907 to track your issue.

justinmk3 avatar Sep 22 '22 20:09 justinmk3

@josh803316 @sambarfoot with https://github.com/aws/aws-toolkit-vscode/pull/3099 , Typescript support should work much better. If you want to try it, we'd love your feedback:

  1. Download and extract buildArtifacts.zip
  2. In VSCode, run Extensions: Install from VSIX to install the *.vsix file. (You can run commands with ctrl-shift-p or cmd-shift-p)
  3. Reload VSCode.

justinmk3 avatar Jan 24 '23 21:01 justinmk3

Thanks @justinmk3 I just installed it and will play around and let you know

josh803316 avatar Jan 24 '23 22:01 josh803316