2023-01-17

spwnn - lambda

AWS lambda's are a boatload of fun.

My first pass, in 2018, was not fun, as it used the old API, which is overly complicated.

The new API "simply" proxies everything into a series of Go maps (hash tables) or similar structure in one of the support languages. "Simply" is quoted because I didn't realize that if I scrolled down the page a bit more in the documentation it told me everything I needed to know, so I spent some extra time writing a lambda echo server to figure out what was what.

In 2022 I used the more modern proxy version.

The new one works as one would expect a web API to work:

https://e36dc3glwa.execute-api.us-east-1.amazonaws.com/default/spwnn?word=contented

I'll probably add more arguments over time, because just seeing internally how a lambda runs is pretty fun.

The new lambda tells you if it is a reused instance of itself, which is a big part of the joy of lambdas.  You can do somewhat expensive initialization which will get reused until AWS decides to retire your lambda.

Lambda start and dictionary load 95.910051ms

_consented_
_contended_
_contented_
_concentrated_

Execution  152.628215ms

Hit reload and:

Lambda reused from previous execution

_consented_
_contended_
_contented_
_concentrated_

Execution  145.135558ms

The execution times are variable, depending on whatever else is going on with the server hosting your lambda.

As a test, I just hit F5 a few times and the runtime varied from 120ms to 160ms. [Update: 2023-01-25: I tried it again, and I'm getting runtimes between 4ms and 60ms. I wonder if your lambda might end up running on significantly different AWS instance types depending on what is available when it first launches.]

Try it out!

NOTE: I haven't posted the code yet because included in the repository is an extremely useful script to create the lambda (which needs to run on an Intel AWS instance - it can be a very cheap one) and another script to update. I'm not sure whether one of the parameters should be secret. I don't think so - I think the secret stuff is already baked into the instance I'm building on. But better to be sure, right? We don't want to post our secrets on Github.

I tried in vain to send enough requests to the lambda so it would start up another one. My code doesn't run long enough to make that easy. (Maybe I'll add a &sleep= parameter for testing that out.)

(2024-05-04 Updated to use ARM64 Lambda)


No comments:

Post a Comment