Locally Debug Lambda Functions with the AWS Toolkit for VS Code

preview_player
Показать описание
AM Grobelny and Nicki Klein demonstrate how to leverage the AWS Toolkit for VS Code to invoke a Lambda function and run debug to support a locally run project.
Рекомендации по теме
Комментарии
Автор

for windows developer, if you want to run:

>sam local generate-event apigateway aws-proxy | pbcopy

, you need to replace "pbcopy" with "clip". so you command change to :

>sam local generate-event apigateway aws-proxy | clip

amirdaydaychallenge
Автор

Anyways the video is obsolete, and after going step by steps, running debug in VSC throws a lots of errors

TomaszSmykowski
Автор

Don't see "Debug locally" ? After some research the SOLUTION: Now, there are no CodeLenses. You push F5 or go to Run -> Start Debugging instead

TomaszSmykowski
Автор

Thanks for posting, great video. Can you provide an example to import an EXISTING lambda function into local environment? I would like to edit w/ vscode

AdiPothuri
Автор

I don't see the options to debug locally on my editor. I have the following VSCode Extensions installed: AWS ToolKit, Python (by Microsoft). Instead, I saw "Add launch configurations". Once I click it, the debugger launch configs are auto populated and I can start debugging as usual but not from clicking the link as shown from the video. I wonder if this is due to a change in AWS ToolKit or not 🤔

Nonetheless, this is a good tutorial for getting started with SAM. I can finally develop Lambda functions locally, thanks for creating this video.

FictionsAndIllusions
Автор

I am new to this so my learning was quite steep because this video doesn't really "at least mention" or "lists in the comments" the following, you need to install awscli, brew sam, and most importantly docker, so sure, all this is scattered all over a crap load of other sites and verbose documentation, for those of you who like me started from scratch and use linux, I feel your pain not knowing these things, remember to install vs code, the extension I wrote before, skip the pbcopy because you may not have it and just copy and paste the json blob manually, ensure also that the docker is running and ideally enabled at boot and "mostly" that the docker group has you (user) inside it or it won't work, ah I forgot !!!! install node too, I tend to prefer nvm to choose the node you want...., lastly, sorry, the brew's sam installation requires for vscode to work, to have the path in PATH, I in my case changed the ~/.profile to add to the path


hope it helps those poor bastards like me

terryfick
Автор

is that was a problem to make record with normal sound?? >(

alexander.gorobets
Автор

Greetings, thanks for the tutorial, is there a template that does not create a default api gateway? Is it possible to load the SAM structure with a lambda function created previously?

davidabad
Автор

Good example of one lambda function but how do we create 2 or more for a complete api locally?

markusmcgee
Автор

The SAM CLI install does NOT install Docker in VSCode or the operating system. Spent a bunch of time working out what was required. Simple omissions that would make this video better. It's a great start but falls flat for a true first timer/Windows user (clip not pbcopy). Also, needed to restart VSCode after installing SAM CLI as the path isn't set.

NigelStratton
Автор

In VSCode under settings enable --> Enable SAM hints in source file

jacobjoy
Автор

I am not able to see Debug, run locally option in VS code. I am on windows and have latest vscode. Also, how can you configure nodejs SAM with typescript?

iamdhison
Автор

I dont see the options "RunLocally Debug Locally and Configure as per the demo, Let me know if I am missing any thing

SrinivasaRaoGurram
Автор

does anyone know what needs to be done to enable Run Locally, Debug Locally and configure options (app.js, between line#16 & 17) in VS code? I didnt find any extension and option in VS code. Any help would be appreciated.

jassi
Автор

What is the process involved for importing custom (non pip) libraries using the toolkit? We have some custom libraries that we currently deployed using lambda layers and would like to bring them into VSCode for local testing, but it seems putting it our venv (for python) doesn't migrate the libraries over to the docker during run/debug. Requirements.txt only works for pip related libraries

wywarren
Автор

Same as everyone, debug function not there and also it seems to have an option now for auto creation in lunch.json format. Please make another video updating this one.

arturofm
Автор

Where they talk about creating event data at around 3:30 into the video can we pass a file with the event.json data vs having go copy it into template and just ref a file? Plus is there a way to pick an event to use at debug time? I have lots of events data to test with and seem painful doing it this way without passing in an event.json file.

markhubers
Автор

isn't the output of the 'sam local generate-event apigateway aws-proxy | pbcopy' command already present in the event.json file in the generated code?

kewlking
Автор

Well, it turned out VS Code simply times out. Pulling the Docker images manually did the trick:
1. For NodeJS
docker pull lambci/lambda:nodejs8.10


2. For Python
docker pull lambci/lambda:python3.7


Debug Locally from VS Code then launches normally, the debugger is successfully attached, and the breakpoints are hit, as expected.

georgesmith
Автор

Thanks for sharing this video. Nicki's mic is probably a little far away so it's difficult to understand sometimes. I have to tweak a few things to be able to follow through the video:
1. In my VS code (v1.40.2), I normally only see "Complexity is 5 Everything is cool!" above the exports.lambdaHandler line. As parifuture pointed out, I have to click "AWS smile" button to be able to see "Run Locally | Debug Locally | Configure". Strange, I have to do it each time I restart VS Code.
2. In Windows 10, you have to use clip instead of pbcopy to copy generated event into clipboard, so >sam local generate-event apigateway aws-proxy | clip

3. Using latest node (12.x) will throw an error "Unsupported javascript runtime: nodeje12.x" when you try "Debug Locally". I had to change it to nodejs8.10 in template.yaml to make it work.

4. As George Smith pointed out, I had to run "docker pull lambci/lambda:nodejs8.10" first, then "Debug Locally". Otherwise, it always times out.

miliu