I'm trying to set up a serverless web app using htmx and FastAPI, but I ran into issues building the deployment zip file on my Windows laptop because of compatibility problems with the Pydantic dependencies. I'm considering using a t2.micro instance running AWS Linux to build this package. I've seen instructions saying to upload the `deployment_package.zip` via the AWS console after building it. Is there a more efficient way to go about this?
5 Answers
You could also look into using GitHub Actions with a bash script that automates the process for you. It's straightforward and will handle the zipping and dependency issues for a Lambda deployment.
Why not just build everything in a Docker container? This way, you're guaranteed to have the correct environment for your dependencies and can push that up once it's built.
Also, make sure that you're including all necessary package files in the zip. Sometimes when you zip your main.py only, you forget important dependencies like Pydantic. Double-check that you're following the AWS packaging guidelines for Python dependencies.
The Pydantic dependencies you're getting on your Windows PC might not work because they're Windows-specific builds. When you do a pip install, make sure to target Linux binaries that are compatible with Lambda. If you're running into issues, consider using Docker to build the package, which ensures you're using the correct environment right from the start.
I had a similar issue with another module. Docker helped me a lot—just set up your script in Docker with a Linux environment and it should work.
If you're looking for a cloud-side solution, AWS CodeBuild might be your best bet. You can use it for free within certain limits, and it even has Lambda executors. This way, you can build and deploy directly without dealing with EC2 instances.
Exactly! I always use Docker for this purpose; it makes managing dependencies so much easier.