1

Is there a way to force AWS to execute a Lambda request coming from an API Gateway resource in a certain execution environment? We're in a use-case where we use one codebase with various models that are 100-300mb, so on their own small enough to fit in the ephemeral storage, but too big to play well together.

Currently, a second invocation with a different model will use the existing (warmed up) lambda function, and run out of storage.

I'm hoping to attach something like a parameter to the request that forces lambda to create parallel versions of the same function for each of the models, so that we don't run over the 512 MB limit and optimize the cold-boot times, ideally without duplicating the function and having to maintain the function in multiple places.

I've tried to investigate Step Machines but I'm not sure if there's an option for parameter-based conditionality there. AWS are suggesting to use EFS to circumvent the ephemeral storage limits, but from what I can find, using EFS will be a lot slower than reading from the ephemeral /tmp/ directory.

T. Altena
  • 752
  • 4
  • 15

1 Answers1

3

To my knowledge: no. You cannot control the execution environments. Only thing you can do is limit the concurrent executions.

So you never know, if it is a single Lambda serving all your events triggered from API Gateway or several running in parallel. You also have no control over which one of the execution environments is serving the next request.

If your issues is the /temp directory limit for AWS Lambda, why not try EFS?

raupach
  • 3,092
  • 22
  • 30
  • Thanks for the quick reply! I'm worried the EFS will slow things down because the read-speed is a lot slower than reading from /tmp/ (according to some of the benchmarking)? The cold-boot penalty of copying over to /tmp/ is something we only incur once, whereas slow read will be incurred every time the function executes. – T. Altena Sep 24 '20 at 15:31
  • @T.Altena Ok, no EFS. What about Elasticache? – raupach Sep 25 '20 at 16:08
  • So after a lot of going back and forth with Amazon support, this turns out to be the case. In my scenario, I've now opted for using Serverless to deploy concurrent functions with identical codebase but different web API's, so that we don't exceed the storage limits. – T. Altena Oct 05 '20 at 07:54
  • @T.Altena Thanks for the feedback! – raupach Oct 05 '20 at 07:55