* Which Category is your question related to? *
Amplify Function
* What AWS Services are you utilizing? *
Lambda, Api Gateway and dynamodb
* Provide additional details e.g. code snippets *
I am new amplify cli and I created a simple api path using amplify api category. The api setup created the function and dynamodb table in turn using the options I gave. I want to know is there a way I can debug the lambda function written locally through visual studio code? I am having tough time understanding the error it gives on cloud watch after I push the resources to cloud using amplify cli. Please suggest.
@divyagowda You could maybe use the amplify function invoke <resoource-name>
functionality?
This is what works for me
lanch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch my Lambda",
"program": "${env:APPDATA}/npm/node_modules/@aws-amplify/cli/bin/amplify",
"args": [
"function",
"invoke",
// replace this with the name of your function
// the folder in amplify/backend/function/
"myamplifyfunction"
],
"console": "integratedTerminal"
}
]
}
Set a breakpoint
, press F5, answer the questions in the _terminal_ and start debugging.
Notice: I'm in Windows with
amplify
installed globally using `npm install -g @aws-amplify/cli
@kstro21 tried your suggestion with no luck. The function runs but the breakpoint will not hit.
@Nbazes take a look at the gif, hope it helps.
@kstro21 I have installed aws-amplify module locally and not globally. When I look through the node_modules aws-amplify package I don't see the file structure the way yo have.
There is no cli folder within @aws-amplify folder.
@divyagowda aws-amplify is one package https://www.npmjs.com/package/aws-amplify the one you use as a dependency for your frontend and mobile applications, and @aws-amplify/cli is another https://www.npmjs.com/package/@aws-amplify/cli the one you use to generate the APIs, auth, GraphQL, Lambdas, etc.
The structure in the gif I posted is from one project generated using @aws-amplify/cli just to show how to debug a function
generated using amplify function add
.
You will need to install @aws-amplify/cli either locally or globally and in your launch.json
set the value of "program"
to the amplify
script.
Globally in Windows, I don't know how it would be in Linux.
"program": "${env:APPDATA}/npm/node_modules/@aws-amplify/cli/bin/amplify",
Locally, I haven't tested.
"program": "${workspaceFolder}/node_modules/@aws-amplify/cli/bin/amplify",
Hope it helps
On a mac I ran which amplify
in console and updated the program path to it and it works for me. IE:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch my Lambda",
"program": "/usr/local/bin/amplify",
"args": [
"function",
"invoke",
// replace this with the name of your function
// the folder in amplify/backend/function/
"LambdaNameHere"
],
"console": "integratedTerminal"
}
]
}
Thx @kstro21
On a mac I ran
which amplify
in console and updated the program path to it and it works for me. IE:{ "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Launch my Lambda", "program": "/usr/local/bin/amplify", "args": [ "function", "invoke", // replace this with the name of your function // the folder in amplify/backend/function/ "LambdaNameHere" ], "console": "integratedTerminal" } ] }
Thx @kstro21
Thank you so much @ryanjones. I am able to debug now. I am on mac had trouble getting the path of the amplify executable.
For me it works, but the breakpoint is ignored.
For me it works, but the breakpoint is ignored.
Same as me. It runs but doesn't hit breakpoints. Any suggestions?
I found a temporary solution.
The main reason behind this issue when the amplify forks a child process it runs the lambda but it doesn't carry the debug parameters into that forked process.
Under
/Users/username/.nvm/versions/node/v11.9.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-nodejs-function-runtime-provider
folder there is invoke.js which runs the Lambda Function. I added these update for running with debug parameters.
Then I listened that port under Google Chrome Node Debug. It worked. I can able to debug under Google Chrome
I think we need open an issue or reopen this one.
hi guys for me (on a mac) amplify mock don't warn me if i have a missing requirement like aws-sdk for example :) try to add it
cd amplify/backend/function/YOUR_FUNCTION_NAME/src && npm i aws-sdk
Most helpful comment
On a mac I ran
which amplify
in console and updated the program path to it and it works for me. IE:Thx @kstro21