Skip to content

Conversation

@ruhrohraggy
Copy link
Contributor

@ruhrohraggy ruhrohraggy commented Oct 23, 2025

Description

Fixes a bug where Lambda layers created with poetry_install, pip_requirements, or npm_requirements incorrectly included both the installed dependencies AND the original source files, even when using
patterns to exclude them.

Root Cause

The module was unconditionally executing a "zip" step for the source path after dependency managers had already zipped their installed packages. This caused both the dependencies and pattern-filtered
source files to be included in the final zip.

Changes

• Modified package.py line 886 to make the source path zip step conditional
• Added comment explaining the logic
• Updated examples/build-package/main.tf to demonstrate using patterns with poetry_install
• Now only zips source path when NOT using dependency managers (pip_requirements, poetry_install, or npm_requirements)
• Dependency managers handle their own zipping correctly

Testing

Created a test Lambda layer with:
• Source files: src/, test/, terraform/, Makefile
• Poetry dependencies: requests and its dependencies
• Patterns excluding all source files

Before fix: Zip contained both python dependencies AND source files
After fix: Zip contains ONLY python/ directory with dependencies

Verified with:

unzip -l builds/*.zip | awk '{print $4}' | cut -d'/' -f1 | sort -u```
# Output: python (only)


## Example Usage
The updated example in examples/build-package/main.tf demonstrates the fix:
```hcl
source_path = [
  {
    path           = "${path.module}/../fixtures/python-app-poetry"
    poetry_install = true
    patterns = [
      "!ignore_please.txt", # Exclude this file
      "!index.py",          # Exclude source code
      "pyproject.toml",     # Include poetry config
      "poetry.lock",        # Include lock file
      "poetry.toml"         # Include poetry settings
    ]
  }
]

Breaking Changes

None. This fix makes the module behave as users would expect when using patterns with dependency managers.

Related Issues

This addresses the issue where patterns were ineffective at excluding source files when poetry_install, pip_requirements, or npm_requirements were enabled.

Ryan Ragnell and others added 4 commits October 23, 2025 14:14
…s/npm_requirements

When poetry_install, pip_requirements, or npm_requirements are enabled,
the dependency managers handle zipping their installed packages correctly.
However, the module was also unconditionally zipping the original source
path, causing both the dependencies AND filtered source files to be
included in the final zip.

This fix makes the source path zip step conditional - it only runs when
NOT using dependency managers, preventing the double-zipping issue.

Fixes issue where patterns were ineffective at excluding source files
when poetry_install was enabled.
Shows how to use patterns to exclude source files while keeping
only poetry configuration files when using poetry_install.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant