Developing AWS Lambda Functions Locally in VS Code

  Рет қаралды 125,099

Travis Media

Travis Media

Күн бұрын

n this video, I want to share the approach I use regularly to develop AWS Lambda functions (and other serverless projects) locally in VS Code using the benefits of AWS's secret sauce, SAM.
AWS SAM, or Serverless Application Model, is a framework that makes managing your serverless AWS service easy. Using the CLI was can create Lambda functions locally, test them, update them, and deploy them, all from our favorite code editor (mine being VS Code).
In this video, we'll create a simple AWS Lambda function locally and I'll show you how to manage it all from your local dev environment.
Video Mentions:
Read the Blog Post: travis.media/d...
MFA Script: gist.github.co...
My #1 Favorite Udemy Course of 2021: geni.us/58VWIe
How to Pass The AWS Solutions Architect: • Pass the AWS Solutions...
How I Learned to Code at 34 and Changed Careers: • How I learned to code ...
*** Get ONE FREE Month on Skillshare. Learn Anything (preferably code 😁) ***
🎓 geni.us/DqB7m
*** I write regularly ***
👉 travis.media
*** Learn to Code Blueprint 6 Month ***
🎓 geni.us/HoswN2
*** FREE EBOOKS ***
📘 bit.ly/2jnH2DP​
LET'S CONNECT!
📰 LinkedIn ➔ / travisdot. .
🐦 Twitter ➔ / travisdotmedia​
🙋🏼‍♂️ Website ➔ travis.media​
#developawslambdafunctions #awssam #serverless #awslambda
** Some of the links in this description are affiliate links that I may get a little cut of. Thank you.

Пікірлер: 65
@viniciushenrique8211
@viniciushenrique8211 Жыл бұрын
Now this is just amazing. I'll use AWS SAM a lot now, thanks! Only thing missing from this tutorial I think would be a small intro on managing Lambda Layers with AWS SAM too.
@TravisMedia
@TravisMedia Жыл бұрын
Noted
@ramonpaolomaran2253
@ramonpaolomaran2253 Жыл бұрын
19:02 and 19:58 You probably know now, but, for the people seeing that now, the AWS SAM CLI, have the command "delete" that delete all resources in the stack that you created. example: "$ sam delete "
@TravisMedia
@TravisMedia Жыл бұрын
Thanks Ramon!
@Usernamesareoutdated
@Usernamesareoutdated 6 ай бұрын
thank you! I was dreading a new uphill battle, but you turned learning SAM into a water slide :D
@veganlife9190
@veganlife9190 2 жыл бұрын
Hey Travis, best sam tutorial I've came across. deserves the sub
@TravisMedia
@TravisMedia 2 жыл бұрын
Thanks!
@sod16
@sod16 3 жыл бұрын
Awesome instructional video. This way of working helps cut out so much nonsense when it comes to working with lambdas!
@asifrasool573
@asifrasool573 2 жыл бұрын
Travis, you are just awesome. I had the issue with importing different python dependencies, mainly snowflake and sql alchemy, I tried a lot with layers and didn't want to shift to linux. I watched this video 3 days ago. But I was stuck in installing Docker, SAM CLI, and also I had Federated AWS Account. I fixed everything and came back to this video. You have saved me. Great tutorial and complete explanation. Thank you so much for this great content..
@chrismacswan4766
@chrismacswan4766 3 жыл бұрын
Oh my god thank you so much for that MFA script. You are a life saver.
@thelonious-dx9vi
@thelonious-dx9vi 2 жыл бұрын
Cheers, this is by far the best available explanation of this. But I really wish there was a more straightforward means of escape from the horrorshow browser IDE -- i.e. without SAM, CloudFormation, etc. I guess there's manually building and pushing zip files, but that's no bed of roses either. I seem to keep landing back in the console IDE when I just need to get something done with Lambda.
@kofio7581
@kofio7581 Жыл бұрын
Thanks Travis, Great Video! BTW - To delete the stack is: sam delete sam-app This was probably added post your video.
@shantisagargebise2883
@shantisagargebise2883 11 ай бұрын
Very well explained. Easy to understand and grasp.
@raghavgautam3379
@raghavgautam3379 2 жыл бұрын
Great man! Thank you so much! You are a great instructor.
@TheMrbird123
@TheMrbird123 2 ай бұрын
Thanks, this video was very helpful!
@waldojams
@waldojams 2 жыл бұрын
That's a neat and modern workflow! Wondering how debugging would work though. Cool thing about a fully functional approach is that it isolates dependencies and work with arguments, which generally make debugging easier. But I have no experience of working with this in a big environment. Looking forward to commit to use in in a bigger project.
@waldojams
@waldojams 2 жыл бұрын
Also interesting to think while I'm doing the research, for the cases where we'd like state coming from RDS (e.g. Postgres), testing locally might become a bit harder. Plus, there's the lambda high concurrency problem when it comes to opening/closing DB connections. At first glance, Lambda might look great for big projects, but when putting all elements on paper, things are not that simple :( I might stick to EC2 and sprinkle some Lambda functions to support it.
@Imperfectwow
@Imperfectwow 6 ай бұрын
cool video, one suggestion making more real world scenario lambda. for instance connecting to rds instance and running some query on db. or updating some paramter in paramer group. when you need to pack depedencis as well like boto3 or pymssql
@szemeibon6258
@szemeibon6258 8 ай бұрын
Thanks Travis for your great tutorial😃
@adityatulsyan1359
@adityatulsyan1359 3 жыл бұрын
It was really helpful, please release more such videos. Thank You.
@demiann4160
@demiann4160 2 жыл бұрын
This was just what I needed. Thanks!
@TallMeDO
@TallMeDO 2 жыл бұрын
game changer! thank you for this sir
@kalmabrooks978
@kalmabrooks978 7 ай бұрын
Awesome tutorial, Which extension are you using on vs code for AWS auto complete and suggestions?
@bordsUK
@bordsUK Жыл бұрын
Great tutorial. I am wondering what if you want to export existing lambda function and debug it locally in vscode. Would love to see that. Keep up the good work 👍
@briandines
@briandines 2 жыл бұрын
Nicely done. Good clean explanation.
@rugeneus
@rugeneus 2 жыл бұрын
Great! It is very clear explanation and very helpful!
@fabiofusco6944
@fabiofusco6944 2 жыл бұрын
Hi Travis, thanks a lot. Great tutorial. I have a question if you don't mind: how can I import dependencies in the local environment? Right now I use Layers, but they seem to not be imported locally. Thanks a lot!
@RohitSharma-x3n
@RohitSharma-x3n Жыл бұрын
That was very helpful
@steveyoo9342
@steveyoo9342 2 жыл бұрын
travis, this was very helpful!
@kaidobit6954
@kaidobit6954 2 жыл бұрын
the aws configure step + your script to get sts generating a token for you could be easily replaced using aws-vault, have a look at that
@apartha77
@apartha77 2 жыл бұрын
sam has cli command "sam delete"
@ev_casey
@ev_casey 10 ай бұрын
a quick sam -h shows can you can do a "sam delete" to remove all resources auto deployed :D .. Thanks for the video!
@MegaJagveer
@MegaJagveer 3 жыл бұрын
Amazing tutorial! Very helpful
@megalordification
@megalordification 2 жыл бұрын
solid video - thank you
@RandyL86
@RandyL86 2 жыл бұрын
Great tutorial! You were super clear and informative. Question for you: how do you get your terminal command line to bring up the past commands you've entered? That seems super useful. I searched but can't find how to enable it.
@TravisMedia
@TravisMedia 2 жыл бұрын
Thanks! Zsh autosuggestions. Check out the video I did a couple months back about the Oh My Zsh plug-ins, should be install instructions there. Actual here’s the link kzbin.info/www/bejne/gnayopyvrd1kbMU
@shauncs
@shauncs 9 ай бұрын
spot on!
@aviahh
@aviahh Жыл бұрын
Great video it helps a ton. one question: if I want to do that with some Python libraries, where should I install those libraries, locally in the same folder (in your example "aws-sam")? something like pip install "library name" -t . ?
@natarajpurudappa882
@natarajpurudappa882 2 жыл бұрын
sam delete --stack-name is to delete the stack
@saeeduchiha5537
@saeeduchiha5537 2 жыл бұрын
In my environment, were devops team locks every thing and use TerraForm for deployment, is there a way to ONLY handle development/testing locally? Without needing the permission to create lambda
@sushantasamantaray7140
@sushantasamantaray7140 3 жыл бұрын
Amazing tutorial
@alialouane7709
@alialouane7709 2 жыл бұрын
Thanks man !
@ksikluks
@ksikluks 2 жыл бұрын
Looks like aws-sam-cli doesn't provide an `aws` cli anymore. Only one called `sam` - which however doesn't come with a `configure` command. So stuck at the very beginning. Trying to follow along and see when it breaks…
@ksikluks
@ksikluks 2 жыл бұрын
Ok, hasn't been mentioned in the video, but you need `brew install awscli` to get it.
@miguellaurente5937
@miguellaurente5937 3 ай бұрын
Nice video, but what's about debuging. How can I do it?
@karlang2637
@karlang2637 Жыл бұрын
If you delete the stack, would the lambda functions get deleted too?
@ganeshkharad
@ganeshkharad 2 жыл бұрын
what if there is an existing Lambda function and we want to import it to the local environment to work?? I don't see template.yml getting downloaded for that. there should be a way to generate it even if lambda is not created with SAM. if you know the answer do share it.
@siddharthshukla3557
@siddharthshukla3557 10 ай бұрын
we dont have access to AWS SAM CLI, is there any other way to develop and test on local?
@mohammedbanabila8515
@mohammedbanabila8515 2 жыл бұрын
thanks for video but i have question , can be use boto3 in sam app
@josemadrid4343
@josemadrid4343 2 жыл бұрын
Can I test a CommonLayer locally using the same steps?
@二一-g4p
@二一-g4p 2 ай бұрын
sam local invoke error:failed to deserialize response from rie. Help ❤❤❤❤
@susmitdey9829
@susmitdey9829 2 жыл бұрын
I get this error while running sam local invoke, looks like an issue with the sam cli REPORT RequestId: eeaadf52-4164-4a85-b63e-8f2a69812e06 Init Duration: 0.80 ms Duration: 205.34 ms Billed Duration: 206 ms Memory Size: 128 MB Max Memory Used: 128 MB {"statusCode":200,"body":"{\"message\":\"hello world\"}"}Exception in thread Thread-2: Traceback (most recent call last): File "threading.py", line 932, in _bootstrap_inner File "threading.py", line 870, in run File "C:\Program Files\Amazon\AWSSAMCLI untime\lib\site-packages\samcli\local\docker\container.py", line 335, in wait_for_logs self._write_container_output(logs_itr, stdout=stdout, stderr=stderr) File "C:\Program Files\Amazon\AWSSAMCLI untime\lib\site-packages\samcli\local\docker\container.py", line 400, in _write_container_output for stdout_data, stderr_data in output_itr: File "C:\Program Files\Amazon\AWSSAMCLI untime\lib\site-packages\docker\types\daemon.py", line 32, in __next__ return next(self._stream) ... err, data = win32file.ReadFile(self._handle, bufsize) pywintypes.error: (109, 'ReadFile', 'The pipe has been ended.')
@CommonSense11111
@CommonSense11111 2 жыл бұрын
How do you set a breakpoint?
@hhjdkdnchidnd
@hhjdkdnchidnd 2 жыл бұрын
hi, how to debug the code?
@musilicks
@musilicks Жыл бұрын
a good developer doesn’t need to debug. they are 100% sure they’re code works. i don’t run or test my code, as I know it will work 100% flawlessly when deployed
@BitBard302
@BitBard302 11 ай бұрын
This content has my full endorsement! If you're interested, there’s a book I’d recommend. "AWS Unleashed: Mastering Amazon Web Services for Software Engineers" by Harrison Quill
@wtf1379
@wtf1379 2 жыл бұрын
Do i have to run "sam build" every time i make any change to the app.py file? i mean when i run that it creates the entire image from scractch rigth? like it installs all my dependencies and such
@TravisMedia
@TravisMedia 2 жыл бұрын
Yes but only run it when you’re ready to push changes, not on every change.
@wtf1379
@wtf1379 2 жыл бұрын
@@TravisMedia so to test locally I can just save app.py and test it with "sam local invoke" without having to rebuild every time? Thank you for the super quick answer btw ahah
@TravisMedia
@TravisMedia 2 жыл бұрын
@@wtf1379 sorry misread, yes I would build it again each time before invoking locally as well.
@TravisMedia
@TravisMedia 2 жыл бұрын
Build before invoking locally and build before deploying.
@ksikluks
@ksikluks 2 жыл бұрын
`sam delete` to delete the whole stack
@damiandanev9271
@damiandanev9271 2 жыл бұрын
A mock service... a waste of time really. Apart from a hardcoded hello-world, SAM is useless. You can't access any databases or any other service for that matter. Define your lambdas as docker containers and use AWS CDK, have your databases running in containers as well. I wonder how long will it take for SAM to be deprecated.
@arianhojat9660
@arianhojat9660 Жыл бұрын
Just curious how do you add env vars to VSCode to debug Lambdas? i have nonprod and prod AWS profiles i can switch in VSCcode to (my aws key/secret pairs). but lets say a nonprod lambda func has other env vars for dev vs qa vs stg env. I want to have a JSON file for each env to use in the nonProd account. Right now when debugging locally, I paste the env key/values under relevant launch.json area: "configurations": [ { "lambda": { "environmentVariables": { ...my Lambda function's key and values here... } } }] Is there a way to specify a file instead of hardcoding the env vars in there? i saw something about "payload": "json" option to use in the environmentVariables area , but not sure if its 100% related to the env params: docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/serverless-apps-run-debug-config-ref.html
Using Python to Automate AWS Services | Lambda and EC2
24:10
Travis Media
Рет қаралды 29 М.
Develop Lambdas Locally in VS Code Using AWS SAM | AWS Lambda Tutorial
15:50
РОДИТЕЛИ НА ШКОЛЬНОМ ПРАЗДНИКЕ
01:00
SIDELNIKOVVV
Рет қаралды 3,3 МЛН
Which One Is The Best - From Small To Giant #katebrush #shorts
00:17
Will A Guitar Boat Hold My Weight?
00:20
MrBeast
Рет қаралды 270 МЛН
AWS SAM Tutorial (with a Lambda Example!)
19:23
Be A Better Dev
Рет қаралды 141 М.
5 Signs of an Inexperienced Self-Taught Developer (and how to fix)
8:40
That's It, I'm Done With Serverless*
23:58
Theo - t3․gg
Рет қаралды 202 М.
Serverless Framework with AWS Lambda Crash Course
1:29:11
Laith Academy
Рет қаралды 111 М.
Top 5 Use Cases For AWS Lambda
12:36
Be A Better Dev
Рет қаралды 82 М.
Introduction to AWS Lambda & Serverless Applications
56:02
Amazon Web Services
Рет қаралды 316 М.
How To Quickly Debug AWS Lambda - VS Code & Serverless Framework
11:59
Dylan Albertazzi
Рет қаралды 19 М.