Serverless deploys full source code of the service for each lambda function

I’m new to the serverless framework and I started learning the framework from the documentation. After setting up a serverless.yml file with three functions and 3 separate handlers for each of those functions, I deployed it in the dev stage.
Now in the AWS account, each of those 3 Lambda functions contains a full source code of the service. Let’s say one function is to return simply hello response and other function is getting data from the DB then why would I need two other files not related to current function in my lambda function source directory.
Can someone explain this if I am missing anything?

Keeping things as simple as possible makes it less likely for there to be an issue. Just zipping everything up and sending it all in one shot is far simpler than trying to determine which function contains which file and potentially get it wrong. Besides, except for taking up a little extra disk space, the additional files do no harm; they do not slow down the execution of your Lambda function.

If you really want to make each function as minimal as possible, you can of course use a plugin to bundle things more efficiently but they add complexity and can cause deployment issues.

1 Like

Hi, I managed to only deploy what I need to the lambda by doing the following.
Add this above your provider section in the yml file

 individually: true

Then in your function definition you can decide what to include/exlude using this. It applies the exclude first and then the include so effectively you exclude everything and then include only the things you want

    handler: functions/myfunction.hello
        - functions/myfunction.js
        - functions/**
1 Like

Thanks. I’ll try this out. I also changed my code to typescript so now it’s not even showing me the source code on the lambda function :grinning:
I think your solution can optimize the code and reduce the function size.