Adventures in AWS Lambda Land - a Migration Gone Well
Hey!
Author here, happy to answer any questions.
TLDR: We moved to Lambda for our async processing, there’s been a few surprises, but it’s been a very good experience overall. The article contains various lessons learned related to local development, secret handling, container images, goroutines in Lambdas, etc.
Did you land on using container images? It’s not clear from the write-up. If so, could you talk a little more about container images vs lambda archives? I like the idea of container images for many reasons:
-
speed boosts, especially with interpreted languages
-
more sensible, obvious build pipeline than lambda archives
-
fits in better with most infrastructure tooling/deployment without having to resort to usage-specific tools like SAM
I understand that these images have the quirk of the lambda runtime, but that’s a fairly small issue from my point of view, especially when compared to lambda archives for, say, Python.
Yeah, we ended up using container images. I honestly don’t see any reason for *not* using them.
We only used them with Go though, so can’t say about interpreted languages.
Container images are fast, they let you have much bigger sizes, and for Go, they’re the only recommended way to go right now (the go1.x runtime is deprecated).
Layers work as well with the trick in the article.
I’m also curious about lambda “resets” (btw, your reset trick is slick!). I haven’t tried this, but is it possible to use lambda versions to achieve the same result? Could you have a “no-op” version rev that forces the lambdas called via the $LATEST version to cycle to a new runtime despite it being equivalent?
Possibly - haven’t played with Lambda versions yet.
I think once any deploy is finished it will cause new invocations to run on new containers. If you need to turn off a lambda it’s the first button in the console, “Throttle”. It sets concurrency to zero, which can be changed back later with the concurrency setting under configuration.
One trick that I also use to reset a lambda is to set maximum invocations (or whatever that is called) to 0!
Damn, super cool solution for running a single binary with the limitation on arguments, very good example of work smarter not harder.
Does this mean despite the architecture being separated, y’all have a single codebase for the server and the drain?
Thanks!
Yeah, precisely. It’s a single binary (albeit getting fairly large, but with container images that’s not an issue).
So, if your async jobs take more than 15 minutes this solution is simply not viable eh?
Assuming that’s the case, I don’t see why you couldn’t use lambda to fire off ECS tasks. Seems like there’s no need for SQS pollers running within ECS as you showed you had before.
> So, if your async jobs take more than 15 minutes this solution is simply not viable eh?
Yeah. In our case we have jobs ranging from 20ms per invocation up to a few minutes per invocations.
> Assuming that’s the case, I don’t see why you couldn’t use lambda to fire off ECS tasks. Seems like there’s no need for SQS pollers running within ECS as you showed you had before.
That’s basically like having a cold start on every invocation and then some, I’d assume (haven’t tried). For invocations < 100 ms that would be quite wasteful.
I see. That’s a good point but then you’re saying that your ECS pollers exist only to combat cold starts. That’s quite a leap for most cases.
I see. That’s a good point but then you’re saying that your ECS pollers exist only to combat cold starts. That’s quite a leap for most cases.
>That’s basically like having a cold start on every invocation and then some
I’m saying even when you run the jobs in ECS, you can still use your approach of dequeuing with Lambda but then rather than doing the work in Lambda, you spin up the ECS task from Lambda. You don’t need pollers running in ECS.
I’ve used versions for Lambdas a while ago and I think it should work. I’ve always been a bit wary of using “latest” as an image or Lambda version - we always use a specific revision.