Building and testing Lambda + Step Function projects locally?

EDIT: Appreciate the responses. Was looking at AWS SAM already, so I’m going to give that a whirl at least. Not sure why the Linux binaries are connected to brew, but that’s a solvable problem.

Haven’t been able to figure this one out.

My company recently pivoted from tomcat applications hosted on containers to “serverless” applications with ALBs if needed.

I’m no expert in this arena, as it’s outside where I’ve built solutions in the past, but it seems straightforward enough. I can’t figure out a way to actually prove out a solution without running a CFT deployment to the test account though, which means

  • 1: I can only try things out on my work laptop, within the rails set up by the company. This is slow and sometimes painful, with multiple levels of review before anything can actually run.

  • 2: Screwups (think infinite loop, erroneously starting process, unbounded output sizes) have a monetary cost to company, and a very real potential life (think “Ability to put food in mouth”) risk to myself.

With normal containerized applications (or non-containerized, because lets face it, Process abstraction versus Machine abstraction doesn’t change how this works), whether it was running inside of a Tomcat servlet, a Node.js process, or just a basic site running in httpd, I can always start a server on one of my scratch boxes, try stuff out, and if it doesn’t work the worst-case scenario is that I delete the VM / wipe the disk on the machine / reboot my dev laptop, and I’m fine.

How do I protect myself in this kind of a model?

The closest I’ve found is to mock out any boto3 / AWS API calls, keep all I/O to stdio/stdout, and code in ALB-style support using one of the httpd-in-a-box libraries that programming languages have picked up recently.

Is that the best I can do?

if you use aws-sam ( by aws ) framework , it has some tools to test lambda locally

i really dislike the notion of local testing. unit test your lambda input and output and get shit done. there is such a thing as bad tests and local step function testing is taking longer than unit testing. do integration tests by all means but use real resources in a proper testing account. don’t block yourself

Speaking only about mocking API calls, I remember seeing a python module called moto (?) that let you do exactly that.

I’ve come up against this problem a lot, and I always hear it from developers I work with. Ultimately the problem (as I see it) with serverless functions is that the best local mock environments (AWS SAM, Serverless Local, Localstack etc etc) don’t come anywhere near close to recreating the true runtime environment to give you justifiable confidence.

Generally a mix of unit testing (using something like moto if you’re working in Python, not sure about similar testing libraries for other langs) and sometimes contract testing can help, but the only achievable way I’ve seen to know your Lambda works as hoped is to do a real deployment into a test account and hammer it. Load testing is important with Lambda IMO, as it’ll surface things that might not be obvious from a few invocations (e.g. cold start issues, memory leaks leading to out of memory problems, funky database connection issues).

Respect your opinion on local testing, although I disagree with it.

but use real resources in a proper testing account.
The key constraint, at least in my view, is that once that testing account is running someone is paying for it. So testing, performance or behavior or otherwise, will be fundamentally limited by how long the testing money lasts.

This is a fundamental paradigm shift from the “throw it on a laptop and try it out” model, where even under the most draconian budgeting standards the test VM / server was as close to free as one could get. A laptop doesn’t even add to a residential electricity bill in a significant way, to say nothing of a hundred or thousand person office.

One practical solution to this problem could be doing a expense reports and reimbursement requests to each developers equivalent of an accounts payable department at their specific company. But anyone who knows how to file those knows that’s a whole new process to add to the SDLC.

And as a corollary to this, the “modern serverless application” seems very similar in design to mainframe applications of 80s and 90s.

We’ve swapped out the single machine / LPAR for a single account and moved the power cord into an Amazon / Google / Microsoft owned facility, but it’s still loose components that trigger each other via events which all run in one ecosystem. Replace Java / Python / Javascript with COBOL and HLASM and I don’t know if people would know the difference.

In those designs, a “rouge function” could be company ruining as the production + test machine was the same box, and an explosive subroutine could knock out the entire company until the big iron was rebooted.
To me, it feels like serverless goes back to that model, and maybe the “just spin up a new Linux / AIX / Solaris box” was really a fluke of the 00’s.

Um … don’t use step functions. Use SNS or SQS or similar. Your AWS bill will thank you.

Why don’t you use linuxacademy aws sandbox, I think they have serverless in the cloud playground. I have tested many things like this like different aws IAM policies, log storage testing before being deployed to prod. I think it might be helpful for your use cases.

OP try placebo

There is something seriously wrong with your company’s processes. There is no excuse for a company not to give developers access to one or more non dev account with reasonable guardrails managed by a service control policy and billing alerts.

Developers spend more time trying to work around a broken process than getting work done. Developers don’t just go to AWS because they want to avoid administering servers, we also want to avoid server administrators.

This comment strikes me as odd. Do you take advantage of AWS organizations? are your prod and test functions in the same account? you’re building up barriers. good luck with that