title: Why is there a size difference when using the AWS Lambda layers vs AWS SAM deployment package
body: <p>I am working on a Lambda function that needs to import <code>SciPy</code> and <code>pyarrow</code>. Since there is an official AWS layer that contains <code>SciPy</code> - <code>AWSLambda-Python38-SciPy1x:14</code> it is used in the function. <code>pyarrow</code> is contained in <a href="https://github.com/awslabs/aws-data-wrangler/releases" rel="nofollow noreferrer"><code>awswrangler</code></a> that was already created as a layer to use in one of the previously made Lambdas.</p>
  <p><a href="https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html" rel="nofollow noreferrer">AWS SAM</a> is used to package and deploy the function. Now there is a pretty interesting difference between copying the contents of the <code>awswrangler</code> layer to the deployment package directory which can be deployed and executed correctly and when both <code>SciPy</code> and <code>awswrangler</code> layers are used in the function. If both layers are used, executing <code>sam deploy</code> gives the following error:</p>
  <pre><code>Layers consume more than the available size of 262144000 bytes (Service: AWSLambdaInternal; Status Code: 400; ...
  </code></pre>
  <p>One thing to note is that when <code>awswrangler</code> layer contents are copied to the deployment package, there is no overlap with the existing contents, so the deployment package is not smaller because f.e. it already contains some of the packages that <code>awswrangler</code> uses.</p>