How To Test your AWS Lambda Function Locally with CDK

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ธ.ค. 2024

ความคิดเห็น • 36

  • @BeABetterDev
    @BeABetterDev  2 ปีที่แล้ว +1

    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 ปีที่แล้ว +3

    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 ปีที่แล้ว +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

  • @MrDadidou
    @MrDadidou 2 ปีที่แล้ว +3

    really nice. i'm wondering how i can integrate my lambda layers with this.
    Need to RTFM a bit

  • @rahulsaha2859
    @rahulsaha2859 2 ปีที่แล้ว +3

    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 ปีที่แล้ว +2

    Great video, very clear and easy to follow!
    Thank you

  • @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?

  • @XStrikeSuper
    @XStrikeSuper 2 ปีที่แล้ว +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?

  •  2 ปีที่แล้ว +1

    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?

  • @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?

  • @sercantor1
    @sercantor1 2 ปีที่แล้ว +1

    That was really helpful man, thank you

  • @ritogaming09
    @ritogaming09 2 ปีที่แล้ว +1

    This is very good . Thanks for this video

  • @nickthiru
    @nickthiru ปีที่แล้ว

    Your videos are in a class of their own! Thanks for teaching! @5:05 😂 I have been there too 🤣

  • @ruggedland
    @ruggedland 2 ปีที่แล้ว +3

    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).

  • @christopherjohncali5237
    @christopherjohncali5237 2 ปีที่แล้ว

    Great video. Is there a link to docs for this? Looking for the javascript-specific implementation.

  • @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 ?

  • @xavierperez3001
    @xavierperez3001 ปีที่แล้ว

    Thank you for this.

  • @marian6040
    @marian6040 2 ปีที่แล้ว

    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.

  • @madrag
    @madrag 2 ปีที่แล้ว

    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?

  • @ToNmAnAyO
    @ToNmAnAyO 2 ปีที่แล้ว +2

    serverless is also a good tool for aws lambdas

  • @ianpogi5
    @ianpogi5 2 ปีที่แล้ว +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.

  • @JohnnysaidWhat
    @JohnnysaidWhat 2 ปีที่แล้ว

    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?

  • @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

  • @pankajjoshi6658
    @pankajjoshi6658 2 ปีที่แล้ว

    Thanks.

  • @geoffrey-rf7pg
    @geoffrey-rf7pg 2 ปีที่แล้ว +1

    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 ปีที่แล้ว +4

      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

  • @Phillip.K.J
    @Phillip.K.J 2 ปีที่แล้ว +1

    keep in mind that you have to install aws-cdk.aws-lambda-python-alpha separately

  • @joesilva-rodriguez9
    @joesilva-rodriguez9 2 ปีที่แล้ว

    Can I do this in TS and cdk? Or is this Sam specific?

    • @geoffrey-rf7pg
      @geoffrey-rf7pg 2 ปีที่แล้ว +1

      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.