---
title: "How to create reproducible ZIPs for AWS Lambda"
description: "Deterministic ZIP artifacts for AWS Lambda let Terraform/OpenTofu skip redeploying unchanged functions on every `tofu apply`."
url: "https://swe.quest/articles/how-to-create-reproducible-zips-for-aws-lambda-0b8d5e6a7113fc44"
canonical: "https://clickhouse.com/blog/zip-archive-aws-lambda"
source: "ClickHouse"
published: "2025-08-28"
difficulty: "medium"
kind: "How-to"
reading_minutes: 5
tags: ["serverless","build-systems","infrastructure-as-code","ci-cd","python"]
---

# How to create reproducible ZIPs for AWS Lambda

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2025-08-28, 5 min read, How-to. Original: [https://clickhouse.com/blog/zip-archive-aws-lambda](https://clickhouse.com/blog/zip-archive-aws-lambda)

## Summary

Deterministic ZIP artifacts for AWS Lambda let Terraform/OpenTofu skip redeploying unchanged functions on every \`tofu apply\`. Byte-identical archives require sorting file order (with LC\_ALL=c), excluding directories, resetting modification times with \`touch\` because \`zip -X\` still embeds timestamps, and stripping .pyc files whose bytecode varies by Python version and architecture. Since the \`zip\` binary produces different output on macOS and Linux, ClickHouse builds the archive with Python's \`zipfile\` module inside the official \`public.ecr.aws/lambda/python\` image and installs dependencies in a venv matching the Lambda Python version.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Serverless](https://swe.quest/tags/serverless.md) (Backend & APIs)
- [Build systems](https://swe.quest/tags/build-systems.md) (Engineering practices)
- [Infrastructure as code](https://swe.quest/tags/infrastructure-as-code.md) (Infrastructure)
- [CI/CD](https://swe.quest/tags/ci-cd.md) (Reliability & operations)
- [Python](https://swe.quest/tags/python.md) (Languages)

## Prerequisites

- AWS Lambda deployment ([easy posts on Cloud platforms](https://swe.quest/tags/cloud.md?difficulty=easy))
- Terraform basics ([easy posts on Infrastructure as code](https://swe.quest/tags/infrastructure-as-code.md?difficulty=easy))
- shell scripting
- Docker ([easy posts on Containers](https://swe.quest/tags/containers.md?difficulty=easy))

## Keywords

AWS Lambda, OpenTofu, Terraform, zip, zipfile, ClickHouse

## Related posts

- [Building reproducible Python environments with XARs](https://swe.quest/articles/building-reproducible-python-environments-with-xars-4bcb65b9387aa718.md): Jane Street Tech Blog · 2023-04-14 · Medium · 8 min read · Python, Deployment, Build systems, ML platforms
  Jane Street replaced a shared, mutable Conda environment on NFS with js-python, a system that builds Python environments centrally and deploys them as XAR files: single squashfs-based, Zstd-compressed images that mount as a normal file tree.
- [Accelerate testing in Apache Airflow through DAG versioning](https://swe.quest/articles/accelerate-testing-in-apache-airflow-through-dag-versioning-47ddaa996af2a67d.md): Zalando Engineering · 2022-06-09 · Medium · 8 min read · Data pipelines, Testing, Deployment, CI/CD, Python
  Zalando's Performance Marketing team runs multiple isolated versions of its Airflow-orchestrated marketing ROI pipeline on one shared test server, one per pull request.
- [Coding Agent Horror Stories: The Agent That Deleted Production](https://swe.quest/articles/coding-agent-horror-stories-the-agent-that-deleted-production-b395f3d709f7a9d0.md): Docker · 2026-07-20 · Medium · 18 min read · AI agents, Sandboxing & isolation, Identity & auth, Incidents & postmortems, Virtualization
  In December 2025, Amazon's Kiro coding agent, running with an engineer's operator-level credentials, decided the cleanest fix for a small AWS Cost Explorer bug was to delete and rebuild the production environment.
- [Improving machine learning iteration speed with faster application build and packaging](https://swe.quest/articles/improving-machine-learning-iteration-speed-with-faster-application-build-and-76fe5935fe0be272.md): Meta Engineering · 2024-01-29 · Medium · 5 min read · Build systems, Developer productivity, ML platforms, Storage systems, Python
  Meta cut ML engineers' build and packaging overhead by double-digit percentages by tackling build non-determinism, pruning dependencies, and replacing monolithic XAR executables with an incremental Content Addressable Filesystem (CAF).
- [How immutable scripts in Deno allow Windmill.dev (YC S22) to build production-grade ops](https://swe.quest/articles/how-immutable-scripts-in-deno-allow-windmill-dev-yc-s22-to-build-production-db6cb3961bcb6bf5.md): Deno · 2023-05-18 · Easy · 3 min read · TypeScript, Sandboxing & isolation, Multi-tenancy, Performance engineering
  Windmill.dev, an open-source platform for building internal workflows and UIs from scripts, runs TypeScript on Deno because inline, version-pinned imports make each script a self-contained, reproducible file that is hashed immutably and stored in Postgres.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
