There are a number of ways as to how we can reduce the package size. Here are the solutions for the issues in question:
- We can compress the shared libraries; this usually enables us to get the best reduction of size.
- We can remove the .pyc files as they do not influence the library work.
- Next, we can remove tests and visualization folders from the libraries as they are not useful in production.
- Next, we can remove libraries that already exist on AWS Lambda.
- Finally, we can check and remove the libraries that aren't used during execution, for example, wheel or PIP libraries.
Now, in the following code, there is the part that finds and compresses all shared libraries. Then, ...