I'm new to AWS and have started building my first Lambda function using Python 3.13. I learned that I can include libraries by using layers. So far, I've set up layers by creating a virtual environment, installing the necessary packages, and copying the package folders into a "python" directory at the root level of a zip file. However, I noticed some guidance suggesting I should also include my lambda_function.py in the root of this zip, which confuses me. Do I need to update the layer zip every time I modify my function code? While it worked for most of my packages without including lambda_function.py, I'm facing issues with the 'cryptography' package and receiving the error about importing 'exceptions' from 'cryptography.hazmat.bindings._rust'. From my research, it seems 'cryptography' relies on my local architecture, which complicates things since I'm on Windows and need to create a Linux-based layer for Lambda. Is there a way to build this layer on a Windows machine, or do I need to use Docker? Any clarity on this would be greatly appreciated!
4 Answers
Another option is to use the AWS SAM CLI. It has built-in commands to build your application and can simulate a Linux environment for your Lambda function, which makes packaging much easier.
One effective way is to use Docker. If you set up a Docker container that matches the Lambda runtime environment, you can easily package your Python libraries there. This approach helps you avoid many pitfalls, especially issues with executable permissions that can arise from using a Windows filesystem.
If you haven't already, consider installing Windows Subsystem for Linux (WSL). This allows you to run a Linux environment directly on your Windows machine, which can simplify creating the Lambda layer. Alternatively, going full Linux could save you a lot of hassle!
You can check out the links provided for guidance on making Python packages compatible with Lambda layers. It's important to ensure that they are built for the Linux architecture since that's what AWS uses.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically