This write-up covers the creation, structure, and deployment of a handler.zip file using modern development tools. 1. File Structure and Contents
: All external libraries (like requests or pandas ) must be installed directly into the root of the ZIP file or within a folder specified by the runtime's path. Configuration Files : Files like .env or local JSON configs. 2. Automated Creation via Terraform [handler].zip
: Automatically packages files into a .serverless directory, often naming the primary artifact based on the function name, though it can be manually specified as handler.zip in the serverless.yml [8]. 4. Best Practices This write-up covers the creation, structure, and deployment
A standard handler.zip package contains the source code and all necessary dependencies required for the function to execute. For a Python-based Lambda, the structure usually looks like this: Configuration Files : Files like
: You can point the aws_lambda_function resource in Terraform directly to the output_path of the archive_file data source.
data "archive_file" "lambda_zip" { type = "zip" source_file = "${path.module}/src/handler.py" output_path = "${path.module}/dist/handler.zip" } Use code with caution. Copied to clipboard : Points to your raw script (e.g., src/handler.py ).
: Generates the handler.zip in a distribution folder [10]. 3. Deployment Integration