-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add create of python package for lambda layer
- Loading branch information
Ru Chern Chong
committed
May 24, 2024
1 parent
27d961e
commit bb57ab2
Showing
4 changed files
with
45 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os | ||
import subprocess | ||
import tempfile | ||
|
||
|
||
def main(temp_dir, zip_file): | ||
root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
package_dir = os.path.join(root_dir, 'venv') | ||
excluded_patterns = ["**/__pycache__/*", "**/bin/*", "**/black*/", "**/pip*/*", "**/pulumi*/*"] | ||
|
||
# Ensure the 'python' directory exists | ||
os.makedirs(package_dir, exist_ok=True) | ||
os.makedirs(temp_dir, exist_ok=True) | ||
|
||
print(f"Temporary directory created at: {temp_dir}") | ||
zip_path = os.path.join(temp_dir, zip_file) | ||
|
||
# Construct the exclusion part of the zip command | ||
exclusion_args = sum([["-x", pattern] for pattern in excluded_patterns], []) | ||
|
||
# Zip the 'python' directory into the temporary directory | ||
subprocess.run(["zip", "-r", zip_path, package_dir, *exclusion_args], stdout=subprocess.DEVNULL) | ||
|
||
print(f"Zipped content is available at {zip_path}") | ||
print(f"Zipped content size {os.path.getsize(zip_path)}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main(tempfile.TemporaryDirectory().name, 'python.zip') |