title: AWS SAM zip contains all dependencies for every Lambda function
body: <p>I am working on a serverless application that has 10 Lambda functions.</p>
  <p>I deploy the code changes using <code>sam build &amp; sam package &amp; sam deploy</code></p>
  <p>SAM creates a zip file of the code and all dependencies and uploads it to S3. This ZIP is downloaded every time a Lambda function is invoked.</p>
  <p>This creates 2 problems.</p>
  <p><strong>1) The build time increases</strong></p>
  <p>Running <code>sam deploy</code> prints <code>File with same data already exists at</code> (Lambda function number - 1) times because it uploads the same ZIP package for all Lambda functions. Since all Lambda functions are in the same repo, the ZIP package is the same for all of them. For some reason SAM doesn't understand this. Are we expected to create a new code repo for every Lambda function?</p>
  <p><strong>2) ZIP file size increases</strong><br />
  As I said above, the ZIP is downloaded every time (if it is a cold start) the Lambda function is invoked. This increases the latency. There is also a <a href="https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html" rel="nofollow noreferrer">limit of 50MB</a> for the ZIP package.</p>
  <p><a href="https://aws.amazon.com/blogs/compute/working-with-aws-lambda-and-lambda-layers-in-aws-sam/" rel="nofollow noreferrer">Lambda Layers</a> seem to be a potential solution but it looks like the setup is not very easy.</p>
  <p>Is there a way to create Lambda function specific ZIP files using SAM? In my case, there would be 10 ZIP files for each Lambda function and each Lambda would download the corresponding ZIP when they're invoked.</p>
  <p>Is it possible to make SAM do a build for each Lambda and only include the dependencies that are actually used in each one instead of packaging all the dependencies together?</p>