I am writing my lambda handlers using serverless.com framework. Does the 2nd way (multiple file handler functions) cause more cold start than the first one?
For example, at 11:00:00am my app calls GET /pets, and at 11:00:30am my app calls POST /store. If both functions are packaged into the same lambda package, then 2nd call won't cause cold start; however, if they are packaged into different lambda package, then 2nd call will be a cold start.
Thanks for sharing
One way to write it is the following
--- single file handlers way ----
...
functions:
listPets:
handler: handler.handler1
events:
- http:
method: get
path: pets
addStore:
handler: handler.handler2
events:
- http:
method: post
path: stores
...
// handler.js
// handle GET /pets
exports.handler1 = async (event) { ... }
// handle POST /stores
exports.handler2 = async (event) { ... }
...
And the other way to organize it is the following:
--- multiple file handlers way ----
...
functions:
listPets:
handler: handler1.handler1
events:
- http:
method: get
path: pets
addStore:
handler: handler2.handler2
events:
- http:
method: post
path: stores
...
// handler1.js
// handle GET /pets
exports.handler1 = async (event) { ... }
// handler2.js
// handle POST /stores
exports.handler2 = async (event) { ... }
...