Reputation: 2731
I have a lambda function with 10 "smaller functions" inside that single lambda which gets accessed by 10 api gateway endpoints.
What are the pros and cons of designing the backend this way? I know it's more difficult to manage all those functions when testing, but how would it compare speedwise to 10 seperate lambda functions?
exports.handler = (event) => {
const path = event.path;
const method = event.httpMethod;
if(path === '/getmail' && method === 'GET'){
return mailQuery(event);
}
if(path === '/getmessagethread' && method === 'GET'){
return getMessageThread(event);
}
if(path === '/replytomessage' && method === 'POST'){
return replyToMessage(event);
}
if(path === '/sendmessage' && method === 'POST'){
return sendMessage(event);
}
. . .
};
Upvotes: 0
Views: 876
Reputation: 2375
imo do whatever you feel comfortable with and that works best for the use case. Here is just my 2 cents on the subject though:
Pros:
Cons:
50 MB (zipped, for direct upload) 250 MB (unzipped, including layers) 3 MB (console editor)
Speedwise I don't think it would make much difference. I don't believe there would be much difference in the time to execute if a function was called as opposed to having the code directly in the handler function.
HTH
-James
Upvotes: 4