Debugging AWS Lambda Locally: Step-by-Step Guide with AWS SAM CLI and VSCode (Part 1)

Поделиться
HTML-код
  • Опубликовано: 28 сен 2024
  • Are you tired of deploying AWS Lambda functions to test your code changes?
    Discover a streamlined approach to your AWS Lambda development in this comprehensive tutorial. Learn how to enhance your efficiency by debugging locally using the potent combination of AWS SAM CLI and VSCode. Follow along as we guide you through Lambda function setup, configuration, and local debugging on your machine. You'll save time and avoid deployment complexities by gaining complete control over your Lambda development. This easy-to-follow guide equips you with a valuable skill every AWS developer should master.
    Welcome to Part 1 of an on going Series. In this episode, we'll leverage AWS SAM to point to a local file housing the lambda handler. This will enable us to launch the Lambda execution environment locally, seamlessly connecting to the lambda handler. Doing so will give us insight into the event and context information populated by the lambda execution environment. Effectively, this provides a window into your Lambda function's internal processes, akin to its execution within the AWS environment.
    Bid farewell to trial and error - unlock efficient debugging techniques for your serverless applications. Whether you're a novice or a seasoned developer, optimizing your development workflow has never been more accessible. Immerse yourself now to elevate your AWS Lambda debugging prowess to new heights!
    Get the code:
    github.com/Tec...

Комментарии • 16

  • @drjones694
    @drjones694 8 месяцев назад +2

    Thank you !!! I'm off to part 2 !!!

  • @ShivaniMalik-l8r
    @ShivaniMalik-l8r 5 дней назад +1

    Can you share some video about docker configuration that is required?

    • @TechTalkWithEric
      @TechTalkWithEric  4 дня назад

      You really shouldn't need to configure it for this example. Running the vscode launch configuration should do everything for you... see the video section about 8 minutes and 50 seconds in.
      Just install docker (desktop) and make sure that the service is running. From the command line if you can issue a command like "docker ps" as long as an error isn't thrown you should be fine. If you get an error like "Cannot connect to the Docker daemon", then docker isn't running and you need to start the service.
      If you're having a specific issue let me know and I'll see if I can walk you through it.

  • @李智诚-h2b
    @李智诚-h2b 9 месяцев назад +1

    非常好的视频,为我节省了大量时间,thanks。

  • @simionbrs
    @simionbrs Год назад +1

    Great video mate. Earned a sub :) BTW, please make a video on how to locally debug an existing Lambda functions and bring it to VSCode. Cheers!

    • @TechTalkWithEric
      @TechTalkWithEric  Год назад +2

      Thanks for the sub! Will do. If you need immediate assistance, take a look at this link:
      disaster-recovery.workshop.aws/en/labs/basics/lambda.html
      It will show you how to export an existing function (assuming you don't already have access to the source via a repository, other means). Then you can unzip it and open it in VSCode. From there use this tutorial to debug it.
      If you have access to the existing function from a repo, just clone it and follow this tutorial.

  • @jeancarlodev
    @jeancarlodev Месяц назад

    Interesting video, what about if i use some packages, i need to setup a venv environment? I found a command with AWS SAM (sam invoke local) ... Which one do you recommend? Thanks for video !

    • @TechTalkWithEric
      @TechTalkWithEric  Месяц назад

      I always use a virtual environment to make my life a little easier (but it's not required). When using SAM I prefer to use the method I outlined in the video to connect vis the sam local invoke. You can use the sam local invoke but then you need also configure the debugger and attach it at runtime... it always seemed like a lot of extra work to me. If I'm not using SAM and instead using the CDK, then there are other tricks out there. I'll make a video on that soon.

  • @ياربعفوكورضاكمحمدطه

    Hi, Im trying to test a lambda locally, but Im struggling with the fact that the DB Im connecting to is only available through AWS VPC. How could test a lambda locally that needs to connect to the VPC in order to connect to the DB and retrieve data fro

    • @TechTalkWithEric
      @TechTalkWithEric  Год назад +2

      In this case you can configure a local db (maybe run a docker container with the db) and configure the lambda function to connect to the local db instead of attempting to connect to VPC. Pass in your db connection information via environment variables.
      So locally you pass in the local db connection and when it's running in AWS you pass in the connection information relative to the environment (dev, prod, etc). This follows a best practice and makes your function more portable between environments.

  • @darround
    @darround Год назад +1

    Very clear explanation. But I tried it with Python runtime and I do not get the code lense options above my Lambda function definition. How do I start the debug when those links are not showing?

    • @TechTalkWithEric
      @TechTalkWithEric  Год назад

      You can use the "Run and Debug" button on the left menu bar in VS Code, then select the Launch Configuration you want from the drop down, then click the green "play" button. Make sure you have a break point set if you want to step into your code, otherwise it will just execute and you really won't have the option to "see" what is going on.
      BTW - I didn't have CodeLens configured in the tutorial, so you won't see it mine either.... you don't need it for debugging.

  • @sbose9999
    @sbose9999 5 месяцев назад +1

    Excellent video.