Developing Lambdas with CDK

I used CDK to create a python based lambda. It adds an api gateway, provides access to database secret and attaches an oracledb layer. It works fine after deploying. My question is about active development. As I’m workin on this lambda what is the best way to deploy this and test my changes? Do I “cdk deploy” every time I need to test it out? Is there a better way to actively develop lambdas? Would sam be better?

Maybe you can use something like gulp?

Have you looked a cdk watch?
https://aws.amazon.com/blogs/developer/increasing-development-speed-with-cdk-watch/

try sst.dev

I do the same. I test by running it locally. You will need to use AWS profile and a way to authenticate into AWS (SSO, access key)

Theres a turorial in the docs about how you can test lambda locally via requests to localhost so you don’t eat up your free invocations and stuff, otherwise you’re doing it right just do cdk deploy at the command line after making changes

Do you have a link to this tutorial?

This is the way

Here’s how we do it:

  1. Create a CDK Pipeline (preferably in a separate Deployment account) that is triggered by pushes to a target branch in Github.

  2. Update your code locally, run unit tests locally, then push your code up. Optionally have additional tests run in CodeBuild, and if they pass then it’ll deploy the lambda in your target environment.

You can generate the CF template using “cdk synth” and then use AWS SAM to run the lambda locally (it uses docker under the hood). The AWS page on this is short, but descriptive enough.

The annoying step is to automate the process of replacing the lambda handler code with the new one when you make changes. This article describes the problem and a potential solution (its for Typescript but the crux is the same)

However, this is not a good idea if your lambdas need to reside in a VPC for testing functionality. Then you should just stick to redeploying.

TLI very nice

Yeah here you go:
https://letmegooglethat.com/?q=testing+lambda+locally&l=1

This looks awesome. Thanks!

cdk deploy {stack} —hotswap

Or with cdk watch as mentioned above

If you’re going to use the LMGT, then rephrase your original comment to something like “there are many tutorials out there..”, not that there’s a specific tutorial and when asked for a link you pull this BS.

It’s THE tutorial from lambda docs, and the first result when you search for “test lambda locally”

This is absolutely the way to do it. I guess the only “downside” is writing the configuration in typescript, which might be annoying in a codebase where the rest is python. But I’d take SST (specifically https://ion.sst.dev AKA v3) over plain CDK any day.

Well your link goes to a Stack Overflow page for me

I was asking, so others that are just now starting their journey could use your knowledge more easily.

You really should reconsider how you conduct yourself in a public forum.

Ah well then my bad and I’m sorry I should delete my mean comment