How To Test your AWS Lambda Function Locally with CDK

  Рет қаралды 43,204

Be A Better Dev

Be A Better Dev

Күн бұрын

Learn how to test your CDK based Lambda function LOCALLY in this step by step tutorial. This walkthrough uses Docker, Sam, and CDK to build and debug our lambda function locally within our IDE. Set breakpoints and analyze your code with this easy to use method.
Looking to get hands on experience building on AWS with a REAL project? Check out my course - The AWS Learning Accelerator! courses.beabet...
🎉SUPPORT BE A BETTER DEV🎉
Become a Patron: / beabetterdev
📚 MY RECOMMENDED READING LIST FOR SOFTWARE DEVELOPERS📚
Clean Code - amzn.to/37T7xdP
Clean Architecture - amzn.to/3sCEGCe
Head First Design Patterns - amzn.to/37WXAMy
Domain Driver Design - amzn.to/3aWSW2W
Code Complete - amzn.to/3ksQDrB
The Pragmatic Programmer - amzn.to/3uH4kaQ
Algorithms - amzn.to/3syvyP5
Working Effectively with Legacy Code - amzn.to/3kvMza7
Refactoring - amzn.to/3r6FQ8U
🎙 MY RECORDING EQUIPMENT 🎙
Shure SM58 Microphone - amzn.to/3r5Hrf9
Behringer UM2 Audio Interface - amzn.to/2MuEllM
XLR Cable - amzn.to/3uGyZFx
Acoustic Sound Absorbing Foam Panels - amzn.to/3ktIrY6
Desk Microphone Mount - amzn.to/3qXMVIO
Logitech C920s Webcam - amzn.to/303zGu9
Fujilm XS10 Camera - amzn.to/3uGa30E
Fujifilm XF 35mm F2 Lens - amzn.to/3rentPe
Neewer 2 Piece Studio Lights - amzn.to/3uyoa8p
💻 MY DESKTOP EQUIPMENT 💻
Dell 34 inch Ultrawide Monitor - amzn.to/2NJwph6
Autonomous ErgoChair 2 - bit.ly/2YzomEm
Autonomous SmartDesk 2 Standing Desk - bit.ly/2YzomEm
MX Master 3 Productivity Mouse - amzn.to/3aYwKVZ
Das Keyboard Prime 13 MX Brown Mechanical- amzn.to/3uH6VBF
Veikk A15 Drawing Tablet - amzn.to/3uBRWsN
🌎 Find me here:
Twitter - / beabetterdevv
Instagram - / beabetterdevv
Patreon - Donations help fund additional content - / beabetterdev
#SoftwareEngineer
#SoftwareDeveloper

Пікірлер: 36
@BeABetterDev
@BeABetterDev 2 жыл бұрын
Looking to become an expert on AWS Lambda? Check out my new course: AWS Lambda - A Practical Guide www.udemy.com/course/aws-lambda-a-practical-guide/?referralCode=F6D1A50467E579C65372
@Johnathanaa7
@Johnathanaa7 2 жыл бұрын
Man doesn't miss. I was reading the blog post by amazon for this like a week ago and you already have a video..
@chrisrabe
@chrisrabe 2 жыл бұрын
That was very useful. I didn't know that you can do this! Thank you. Here I was testing my lambdas via the lamba management console like a noob
@rahulsaha2859
@rahulsaha2859 2 жыл бұрын
A great video. Always wanted to test lambda locally.
@yatsuk
@yatsuk 2 жыл бұрын
Just use plain unit testing and mock remote resources - it will be much faster. At least for me, it works better than sam-local.
@nachum800
@nachum800 2 жыл бұрын
Great video, very clear and easy to follow! Thank you
@nickthiru
@nickthiru 11 ай бұрын
Your videos are in a class of their own! Thanks for teaching! @5:05 😂 I have been there too 🤣
@sercantor1
@sercantor1 2 жыл бұрын
That was really helpful man, thank you
@BeABetterDev
@BeABetterDev 2 жыл бұрын
You're very welcome
@ritogaming09
@ritogaming09 2 жыл бұрын
This is very good . Thanks for this video
@BeABetterDev
@BeABetterDev 2 жыл бұрын
You're very welcome!
@MrDadidou
@MrDadidou 2 жыл бұрын
really nice. i'm wondering how i can integrate my lambda layers with this. Need to RTFM a bit
@XStrikeSuper
@XStrikeSuper 2 жыл бұрын
Will you also do a video what the best way to do an integration test to hit real AWS service? Eg: Send a message to SQS which trigger a lambda function to add item in DynamoDb. How do we test this as part of integration test?
@xavierperez3001
@xavierperez3001 Жыл бұрын
Thank you for this.
@ruggedland
@ruggedland 2 жыл бұрын
For the simple function used in this video, you don’t really need CDK. SAM can do everything and Sam local invoke will work too. I believe CDK is necessary when you lambda need to invoke other AWS services like s3 or dynamoDB
@0xccd
@0xccd 2 жыл бұрын
You can do that with CDK and SAM. Under the hood, everything is CloudFormation. I use CDK with TypeScript 99% of the time even when my lambdas are written in other languages (Python, Rust, etc.). Auto-completion, references, docs, type checks, and so on in TS is absolutelly a time saver (+ the benefit of using OOP for yor resources).
2 жыл бұрын
Nice trick, but what about when we have to do some stuff with Aurora, DynamoDB or S3 inside the lambda function. And when is using API Gateway using Cognito Authorizers ? Will always need to set CLI session?
@marian6040
@marian6040 Жыл бұрын
Excelent. I needed this. Thanks. Could you please make a video about awssdkcalls with cdk python? I’m having a hard time understanding how to find the different information about it.
@christopherjohncali5237
@christopherjohncali5237 2 жыл бұрын
Great video. Is there a link to docs for this? Looking for the javascript-specific implementation.
@madrag
@madrag Жыл бұрын
Nice tutorial. Can you make simialar to this but this time how to debug cdk app (python) with context (for example -c stage=prepord) in visual studio code? How correctly setup lunch.json?
@damianbartholomew3930
@damianbartholomew3930 Жыл бұрын
Great video. At 2:18, you noted we could add other requirements (in my case xmltodict). Your example works and I can add xmltodict with a cdk synth. However, in my Lambda an exception is thrown that the xmltodict resource could not be found. Is this something simple?
@pankajjoshi6658
@pankajjoshi6658 2 жыл бұрын
Thanks.
@ToNmAnAyO
@ToNmAnAyO 2 жыл бұрын
serverless is also a good tool for aws lambdas
@djstacktrace
@djstacktrace Жыл бұрын
Is it possible to test locally via sam if os.environ is added to the code e.g. DB_HOST, DB_PORT for function env variables?
@Phillip.K.J
@Phillip.K.J 2 жыл бұрын
keep in mind that you have to install aws-cdk.aws-lambda-python-alpha separately
@JohnnysaidWhat
@JohnnysaidWhat Жыл бұрын
Do you recommend this process for building step functions? I would think since the step function new visual editor generates a json definition file it’s easy enough to through into version control. Then you can use this to test individual lambdas within the step function locally. Does that makes sense? Or is there a way to use the json definition in this framework without any cdk and still have it included in deployments?
@ianpogi5
@ianpogi5 2 жыл бұрын
Thanks for the video! For real life scenario, how do you run this for multiple microservices with API gateway? I ask because I want to unify all my IaaC to CDK but the in ability to test locally stops me from doing that. Serverless framework + serverless-offline plugin does this very easily.
@0xccd
@0xccd 2 жыл бұрын
Good question. Please share the answer if you know how to do it
@ianpogi5
@ianpogi5 2 жыл бұрын
@@0xccd My solution is to keep using Serverless framework + serverless-offline plugin.
@10SURA
@10SURA Жыл бұрын
What if the lambda connected to dynamo db ? will be connected to the AWS DynamoDB or we need to connect have local dynamo db instance up and running in this case ?
@Garejoor
@Garejoor 2 жыл бұрын
if you are using websocket this doesn't work - try to make the decoupled enough so the websocket dependency is not a must
@geoffrey-rf7pg
@geoffrey-rf7pg 2 жыл бұрын
This is good for basic lambdas but usually when you have to deal with other stuff such as SSM parameters, it becomes really dificult to test it this way, in my own experience.
@kcrikk5818
@kcrikk5818 2 жыл бұрын
Check out Moto python library. It allows for mocking AWS resources locally, as a server or at runtime. So you can mock SSM, etc...I think it's a far better way than using Sam, Docker, etc....way less complicated to use Moto, and Moto support is amazing, they will even take your code if something doesn't work and try to help you out and set up a project to check out any issue.
@geoffrey-rf7pg
@geoffrey-rf7pg 2 жыл бұрын
@@kcrikk5818 I’ll give it a try. Thanks
@joesilva-rodriguez9
@joesilva-rodriguez9 2 жыл бұрын
Can I do this in TS and cdk? Or is this Sam specific?
@geoffrey-rf7pg
@geoffrey-rf7pg 2 жыл бұрын
This is a SAM specific feature, there are some libraries out there that try to fix this issue but I haven't seen anything good for complex scenarios yet. I'd normally stick to a simple test file where I import my app.py/index.js/index.ts file and call the handler with a test event. Pretty simple but so far I have had great results.
🆕 UNIT TEST your Step Functions with the Mocked Service Integrations
21:03
Flipping Robot vs Heavier And Heavier Objects
00:34
Mark Rober
Рет қаралды 41 МЛН
didn't manage to catch the ball #tiktok
00:19
Анастасия Тарасова
Рет қаралды 31 МЛН
Getting Started with AWS CDK and Python | Step by Step Tutorial
24:44
Be A Better Dev
Рет қаралды 89 М.
Developing AWS Lambda Functions Locally in VS Code
20:22
Travis Media
Рет қаралды 126 М.
How to test and develop AWS lambda functions locally with nodejs?
29:36
BiteSize Academy
Рет қаралды 17 М.
AWS CDK Crash Course for Beginners
1:07:31
Be A Better Dev
Рет қаралды 52 М.
How to Run a Python Docker Image on AWS Lambda
13:08
pixegami
Рет қаралды 34 М.
Testing Local AWS cloud with Localstack! | Tutorial
21:22
Tech with Marco
Рет қаралды 4,4 М.
How to test AWS Lambda Locally using SAM or LocalStack with CDK
12:30
Simply Serverless
Рет қаралды 10 М.
Flipping Robot vs Heavier And Heavier Objects
00:34
Mark Rober
Рет қаралды 41 МЛН