Skip to content

Commit f58cfcb

Browse files
committed
python3 compatibility in helpers.read
1 parent df47695 commit f58cfcb

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The *Python-Lambda* library takes away the guess work of developing your Python-
3434
Requirements
3535
============
3636

37+
* Python 2.7 & 3.6 (At the time of writing this, AWS Lambda only supports Python 2.7/3.6).
3738
* Pip (~8.1.1)
3839
* Virtualenv (~15.0.0)
3940
* Virtualenvwrapper (~4.7.1)

aws_lambda/aws_lambda.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ def create_function(cfg, path_to_zip_file):
343343
"""Register and upload a function to AWS Lambda."""
344344

345345
print("Creating your new Lambda function")
346-
byte_stream = read(path_to_zip_file)
346+
byte_stream = read(path_to_zip_file, binary_file=True)
347347
aws_access_key_id = cfg.get('aws_access_key_id')
348348
aws_secret_access_key = cfg.get('aws_secret_access_key')
349349

@@ -381,7 +381,7 @@ def update_function(cfg, path_to_zip_file):
381381
"""Updates the code of an existing Lambda function"""
382382

383383
print("Updating your Lambda function")
384-
byte_stream = read(path_to_zip_file)
384+
byte_stream = read(path_to_zip_file, binary_file=True)
385385
aws_access_key_id = cfg.get('aws_access_key_id')
386386
aws_secret_access_key = cfg.get('aws_secret_access_key')
387387

aws_lambda/helpers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ def mkdir(path):
99
os.makedirs(path)
1010

1111

12-
def read(path, loader=None):
13-
with open(path) as fh:
12+
def read(path, loader=None, binary_file=False):
13+
open_mode = 'rb' if binary_file else 'r'
14+
with open(path, mode=open_mode) as fh:
1415
if not loader:
1516
return fh.read()
1617
return loader(fh.read())

0 commit comments

Comments
 (0)