Skip to content
This repository was archived by the owner on Mar 15, 2026. It is now read-only.

Commit e73ab40

Browse files
committed
Adding the ability to copy files before zipping up
1 parent 76ee21c commit e73ab40

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ docs/_build/
5757

5858
# PyBuilder
5959
target/
60+
61+
.idea

aws_lambda/aws_lambda.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def cleanup_old_versions(src, keep_last_versions):
6262
e.message))
6363

6464

65-
def deploy(src, local_package=None):
65+
def deploy(src, local_package=None, copy_file=None):
6666
"""Deploys a new function to AWS Lambda.
6767
6868
:param str src:
@@ -80,7 +80,7 @@ def deploy(src, local_package=None):
8080
# folder then add the handler file in the root of this directory.
8181
# Zip the contents of this folder into a single file and output to the dist
8282
# directory.
83-
path_to_zip_file = build(src, local_package)
83+
path_to_zip_file = build(src, local_package, copy_file)
8484

8585
if function_exists(cfg, cfg.get('function_name')):
8686
update_function(cfg, path_to_zip_file)
@@ -146,7 +146,7 @@ def init(src, minimal=False):
146146
copy(destination, src)
147147

148148

149-
def build(src, local_package=None):
149+
def build(src, local_package=None, copy_file=None):
150150
"""Builds the file bundle.
151151
152152
:param str src:
@@ -196,6 +196,20 @@ def build(src, local_package=None):
196196
# Copy handler file into root of the packages folder.
197197
copyfile(f, os.path.join(path_to_temp, filename))
198198

199+
if copy_file:
200+
if os.path.isfile(copy_file):
201+
copyfile(copy_file,
202+
os.path.join(path_to_temp, os.path.basename(copy_file)))
203+
elif os.path.isdir(copy_file):
204+
copy_dir_name = os.path.basename(copy_file)
205+
dest_dir = os.path.join(path_to_temp, copy_dir_name)
206+
207+
from shutil import rmtree, copytree
208+
209+
if os.path.exists(dest_dir):
210+
rmtree(dest_dir)
211+
copytree(copy_file, dest_dir)
212+
199213
# Zip them together into a single file.
200214
# TODO: Delete temp directory created once the archive has been compiled.
201215
path_to_zip_file = archive('./', path_to_dist, output_filename)

scripts/lambda

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def init(folder):
2929
@click.command(help="Bundles package for deployment.")
3030
@click.option('--local-package', default=None, help='Install local package as well.', type=click.Path())
3131
def build(local_package):
32-
aws_lambda.build(CURRENT_DIR, local_package)
32+
aws_lambda.build(CURRENT_DIR, local_package, copy_file=None)
3333

3434

3535
@click.command(help="Run a local test of your function.")
@@ -41,8 +41,9 @@ def invoke(event_file, verbose):
4141

4242
@click.command(help="Register and deploy your code to lambda.")
4343
@click.option('--local-package', default=None, help='Install local package as well.', type=click.Path())
44-
def deploy(local_package):
45-
aws_lambda.deploy(CURRENT_DIR, local_package)
44+
@click.option('--copy-file', default=None, help='Copies file/directory', type=click.Path())
45+
def deploy(local_package, copy_file):
46+
aws_lambda.deploy(CURRENT_DIR, local_package, copy_file)
4647

4748

4849
@click.command(help="Delete old versions of your functions")

0 commit comments

Comments
 (0)