Sam
Sam

Reputation: 6265

Can a Lambda container host more than one function at once?

Is it possible for multiple Lambda function definitions to be deployed to the same container instance?

I understand that a given Lambda container will only execute at most one function at a time, but wanted to understand the composition relationship between functions and the host container.

For example, in the Serverless App project type for Visual Studio with the AWS Toolkit Extensions, it's possible to define multiple functions in a single project, but do these get deployed via CloudFormation into separate containers or a single container representing the project?

Upvotes: 6

Views: 2846

Answers (4)

pellyadolfo
pellyadolfo

Reputation: 991

I did this by using ExpressJS+NodeJS. Every function is a different ExpressJS route. However, so far I have not been able to do it with Spring Cloud Function.

Upvotes: 0

Arieh Kovler
Arieh Kovler

Reputation: 67

CloudFormation will deploy the functions to the same AWS account. This is happening at the AWS user account level. It's not running the functions.

Lambdas are event-driven and only run when they are triggered. Every instance of a Lambda is standalone as far as the user experiences it, and is "deployed in its own container" when triggered.

Maybe something deeper is happening under the abstraction layers but that's how you'll experience it.

Upvotes: 0

AlexK
AlexK

Reputation: 1420

There's not an official document on the matter, but I will share what I have gathered the past years from Docs/Posts/Conferences:

Lambda functions are "framework" (or something like it, just that word is the closest I can think of and the only one I have heard from AWS representative) on top of a Containerization service. Every time you call lambda function a container is being run (it could be an existing one, put on hold - adds performance boost, or an entirely new one, you can never know which one it is.)

You could assume, the container instance (using instance as it is used in ECS, a host machine) is the same, having in mind there are some workarounds for DB Connection pooling and things of the like, but nobody guarantees you that.

Upvotes: 0

thomasmichaelwallace
thomasmichaelwallace

Reputation: 8474

I think it might help to separate out the process:

  • A lambda deployment is a zip file of code, and a matching configuration. In the case of your Serverless App project type, when you have multiple lambda functions to a project, you're creating multiple deployments.
  • A lambda instance is a running version of a deployment hosted inside of a container. Only one lambda instance is allowed in a container, that is an AWS guarantee. This means that you can never get access to code/memory/files outside of the currently running instance (either yours or anyone else's!)

As an optimisation AWS does re-use instances by freezing and thawing the container. This is because it's expensive to start a fresh container, copy the deployment, and do the init code of the deployment (known as the cold start).

Upvotes: 4

Related Questions