Skip to content

Commit 4f44148

Browse files
committed
Bundle all files in top level project directory
1 parent c7f8f45 commit 4f44148

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

aws_lambda/aws_lambda.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,11 @@ def deploy(src):
2929
path_to_config_file = os.path.join(src, 'config.yaml')
3030
cfg = read(path_to_config_file, loader=yaml.load)
3131

32-
# Get the absolute path to the output directory and create it if it doesn't
33-
# already exist.
34-
dist_directory = cfg.get('dist_directory', 'dist')
35-
path_to_dist = os.path.join(src, dist_directory)
36-
mkdir(path_to_dist)
37-
38-
# Combine the name of the Lambda function with the current timestamp to use
39-
# for the output filename.
40-
function_name = cfg.get('function_name')
41-
output_filename = "{0}-{1}.zip".format(timestamp(), function_name)
42-
4332
# Copy all the pip dependencies required to run your code into a temporary
4433
# folder then add the handler file in the root of this directory.
4534
# Zip the contents of this folder into a single file and output to the dist
4635
# directory.
47-
path_to_zip_file = build(src, path_to_dist, output_filename)
36+
path_to_zip_file = build(src)
4837

4938
if function_exists(cfg, cfg.get('function_name')):
5039
update_function(cfg, path_to_zip_file)
@@ -112,7 +101,7 @@ def init(src, minimal=False):
112101
copy(path_to_file, src)
113102

114103

115-
def build(src, path_to_dist, output_filename):
104+
def build(src):
116105
"""Builds the file bundle.
117106
118107
:param str path_to_handler_file:
@@ -126,6 +115,17 @@ def build(src, path_to_dist, output_filename):
126115
path_to_config_file = os.path.join(src, 'config.yaml')
127116
cfg = read(path_to_config_file, loader=yaml.load)
128117

118+
# Get the absolute path to the output directory and create it if it doesn't
119+
# already exist.
120+
dist_directory = cfg.get('dist_directory', 'dist')
121+
path_to_dist = os.path.join(src, dist_directory)
122+
mkdir(path_to_dist)
123+
124+
# Combine the name of the Lambda function with the current timestamp to use
125+
# for the output filename.
126+
function_name = cfg.get('function_name')
127+
output_filename = "{0}-{1}.zip".format(timestamp(), function_name)
128+
129129
path_to_temp = mkdtemp(prefix='aws-lambda')
130130
pip_install_to_target(path_to_temp)
131131

@@ -134,18 +134,22 @@ def build(src, path_to_dist, output_filename):
134134
if not output_filename.endswith('.zip')
135135
else output_filename)
136136

137-
# Determine the filename and absolute path to the handler module.
138-
handler = cfg.get('handler')
139-
filename = get_handler_filename(handler)
140-
path_to_handler_file = os.path.join(src, filename)
137+
files = []
138+
for filename in os.listdir(src):
139+
if os.path.isfile(filename):
140+
if filename == '.DS_Store':
141+
continue
142+
if filename == 'config.yaml':
143+
continue
144+
files.append(os.path.join(src, filename))
141145

142146
# "cd" into `temp_path` directory.
143147
os.chdir(path_to_temp)
148+
for f in files:
149+
_, filename = os.path.split(f)
144150

145-
_, filename = os.path.split(path_to_handler_file)
146-
147-
# Copy handler file into root of the packages folder.
148-
copyfile(path_to_handler_file, os.path.join(path_to_temp, filename))
151+
# Copy handler file into root of the packages folder.
152+
copyfile(f, os.path.join(path_to_temp, filename))
149153

150154
# Zip them together into a single file.
151155
# TODO: Delete temp directory created once the archive has been compiled.

0 commit comments

Comments
 (0)