From 1a51f2e919ad645baa951bed9276b2784c749f57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Miguel=20Neves?= Date: Sun, 14 Jun 2020 21:35:19 +0100 Subject: [PATCH 1/7] fix deploy with --no_venv --- zappa/cli.py | 3 ++- zappa/core.py | 47 ++++++++++++++++++++++++++--------------------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/zappa/cli.py b/zappa/cli.py index 2820eacba..9e448518a 100755 --- a/zappa/cli.py +++ b/zappa/cli.py @@ -2122,7 +2122,8 @@ def load_settings(self, settings_file=None, session=None): runtime=self.runtime, tags=self.tags, endpoint_urls=self.stage_config.get('aws_endpoint_urls',{}), - xray_tracing=self.xray_tracing + xray_tracing=self.xray_tracing, + no_venv=self.vargs.get("no_venv") ) for setting in CUSTOM_SETTINGS: diff --git a/zappa/core.py b/zappa/core.py index faa8779fb..b34f8f155 100644 --- a/zappa/core.py +++ b/zappa/core.py @@ -250,7 +250,8 @@ def __init__(self, runtime='python3.6', # Detected at runtime in CLI tags=(), endpoint_urls={}, - xray_tracing=False + xray_tracing=False, + no_venv=False ): """ Instantiate this new Zappa instance, loading any custom credentials if necessary. @@ -289,6 +290,7 @@ def __init__(self, self.endpoint_urls = endpoint_urls self.xray_tracing = xray_tracing + self.no_venv = no_venv # Some common invocations, such as DB migrations, # can take longer than the default. @@ -522,34 +524,37 @@ def create_lambda_zip( self, if not 'concurrent' in exclude: exclude.append('concurrent') - def splitpath(path): - parts = [] - (path, tail) = os.path.split(path) - while path and tail: - parts.append(tail) + to_exclude = [] + if not self.no_venv: + def splitpath(path): + parts = [] (path, tail) = os.path.split(path) - parts.append(os.path.join(path, tail)) - return list(map(os.path.normpath, parts))[::-1] - split_venv = splitpath(venv) - split_cwd = splitpath(cwd) - - # Ideally this should be avoided automatically, - # but this serves as an okay stop-gap measure. - if split_venv[-1] == split_cwd[-1]: # pragma: no cover - print( - "Warning! Your project and virtualenv have the same name! You may want " - "to re-create your venv with a new name, or explicitly define a " - "'project_name', as this may cause errors." - ) + while path and tail: + parts.append(tail) + (path, tail) = os.path.split(path) + parts.append(os.path.join(path, tail)) + return list(map(os.path.normpath, parts))[::-1] + split_venv = splitpath(venv) + split_cwd = splitpath(cwd) + + # Ideally this should be avoided automatically, + # but this serves as an okay stop-gap measure. + if split_venv[-1] == split_cwd[-1]: # pragma: no cover + print( + "Warning! Your project and virtualenv have the same name! You may want " + "to re-create your venv with a new name, or explicitly define a " + "'project_name', as this may cause errors." + ) + to_exclude = [split_env[-1]] # First, do the project.. - temp_project_path = tempfile.mkdtemp(prefix='zappa-project') + temp_project_path = tempfile.mkdtemp(prefix='zappa-project') if not slim_handler: # Slim handler does not take the project files. if minify: # Related: https://github.com/Miserlou/Zappa/issues/744 - excludes = ZIP_EXCLUDES + exclude + [split_venv[-1]] + excludes = ZIP_EXCLUDES + exclude + to_exclude copytree(cwd, temp_project_path, metadata=False, symlinks=False, ignore=shutil.ignore_patterns(*excludes)) else: copytree(cwd, temp_project_path, metadata=False, symlinks=False) From 0adb7041359f7bea2b97cdf1962ba7d6116b4053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Miguel=20Neves?= Date: Tue, 14 Jul 2020 19:23:04 +0100 Subject: [PATCH 2/7] fix typo --- zappa/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zappa/core.py b/zappa/core.py index b34f8f155..bd74373fe 100644 --- a/zappa/core.py +++ b/zappa/core.py @@ -545,7 +545,7 @@ def splitpath(path): "to re-create your venv with a new name, or explicitly define a " "'project_name', as this may cause errors." ) - to_exclude = [split_env[-1]] + to_exclude = [split_venv[-1]] # First, do the project.. temp_project_path = tempfile.mkdtemp(prefix='zappa-project') From 5923b0efa6f6ead2fdebce67677a21d050dcfc2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Miguel=20Neves?= Date: Tue, 14 Jul 2020 21:15:55 +0100 Subject: [PATCH 3/7] vargs might not be there --- zappa/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zappa/cli.py b/zappa/cli.py index 9e448518a..6a410818a 100755 --- a/zappa/cli.py +++ b/zappa/cli.py @@ -2123,7 +2123,7 @@ def load_settings(self, settings_file=None, session=None): tags=self.tags, endpoint_urls=self.stage_config.get('aws_endpoint_urls',{}), xray_tracing=self.xray_tracing, - no_venv=self.vargs.get("no_venv") + no_venv=self.vargs.get("no_venv") if self.vargs else None ) for setting in CUSTOM_SETTINGS: From cd745c8e8901f8134e34faa0e215550820f6017c Mon Sep 17 00:00:00 2001 From: monkut Date: Thu, 1 Oct 2020 16:49:24 +0900 Subject: [PATCH 4/7] Use Content-Encoding to identify if data is binary When using _whitenoise_ for caching, which provides compression, binary types may include mimetypes, "text/", "application/json": - response.mimetype.startswith("text/") - response.mimetype == "application/json" Assuming that Content-Encoding will be set (as whitenoise apparently does) this allows compression to be applied by the application for "text/" and "application/json". About Content-Encoding: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding --- zappa/handler.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zappa/handler.py b/zappa/handler.py index 78a31cfda..e06a74fbf 100644 --- a/zappa/handler.py +++ b/zappa/handler.py @@ -549,9 +549,9 @@ def handler(self, event, context): zappa_returndict.setdefault('statusDescription', response.status) if response.data: - if settings.BINARY_SUPPORT and \ - not response.mimetype.startswith("text/") \ - and response.mimetype != "application/json": + content_encoding = response.headers.get("Content-Encoding", None) + binary_encodings = ("gzip", "compress", "deflate", "br") + if settings.BINARY_SUPPORT and content_encoding in binary_encodings: zappa_returndict['body'] = base64.b64encode(response.data).decode('utf-8') zappa_returndict["isBase64Encoded"] = True else: From 7f156ae485dcad9b4a7722fc679888bf22058bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Miguel=20Neves?= Date: Fri, 2 Oct 2020 16:59:17 +0100 Subject: [PATCH 5/7] 0.52.0 release --- CHANGELOG.md | 5 ++++- zappa/__init__.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 249d12c6d..10d067f98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Zappa Changelog -## next +## 0.52.0 +* Remove dateutil version restriction +* Fix failed downloads of wheel packages with non-alphanumeric characters +* Last release from Miserlou/Zappa * Removed references to zappa.io ## 0.51.0 diff --git a/zappa/__init__.py b/zappa/__init__.py index 2a1d400bc..c0fe60dd3 100644 --- a/zappa/__init__.py +++ b/zappa/__init__.py @@ -8,4 +8,4 @@ 'Zappa (and AWS Lambda) support the following versions of Python: {}'.format(formatted_supported_versions)) raise RuntimeError(err_msg) -__version__ = '0.51.0' +__version__ = '0.52.0' From 6c66a6c49ce06ff5f410dffabbcce5d94e44258e Mon Sep 17 00:00:00 2001 From: monkut Date: Thu, 28 Jan 2021 09:09:12 +0900 Subject: [PATCH 6/7] Update to handle error cases Include fallbacks for cases: - try binary, fail to text - try text, fail to binary --- zappa/handler.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/zappa/handler.py b/zappa/handler.py index e06a74fbf..6886f1b1b 100644 --- a/zappa/handler.py +++ b/zappa/handler.py @@ -552,10 +552,21 @@ def handler(self, event, context): content_encoding = response.headers.get("Content-Encoding", None) binary_encodings = ("gzip", "compress", "deflate", "br") if settings.BINARY_SUPPORT and content_encoding in binary_encodings: - zappa_returndict['body'] = base64.b64encode(response.data).decode('utf-8') - zappa_returndict["isBase64Encoded"] = True + try: + zappa_returndict["body"] = base64.b64encode(response.data).decode("utf8") + zappa_returndict["isBase64Encoded"] = True + except UnicodeDecodeError as e: + logger.exception(e) + logger.error(f"Unable to decode resulting base64 encoded response.data as 'utf8': response.data={response.data}") + logger.warning("Using response.get_data(as_text=True)") + zappa_returndict["body"] = response.get_data(as_text=True) else: - zappa_returndict['body'] = response.get_data(as_text=True) + try: + zappa_returndict["body"] = response.get_data(as_text=True) + except UnicodeDecodeError: + # If data can't be decoded as utf-8, try processing as binary + zappa_returndict["body"] = base64.b64encode(response.data).decode("utf8") + zappa_returndict["isBase64Encoded"] = True zappa_returndict['statusCode'] = response.status_code if 'headers' in event: From 14658ce60ecbe4a58a523d7585ed3c8a7e269e8d Mon Sep 17 00:00:00 2001 From: monkut Date: Thu, 28 Jan 2021 09:46:04 +0900 Subject: [PATCH 7/7] =?UTF-8?q?=F0=9F=94=80=20merge=20with=20Miserlou/Zapp?= =?UTF-8?q?a=200.52.0=20:wrench:=20clean-up=20BINARY=5FSUPPORT=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zappa/handler.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/zappa/handler.py b/zappa/handler.py index 6886f1b1b..944e5c326 100644 --- a/zappa/handler.py +++ b/zappa/handler.py @@ -565,6 +565,10 @@ def handler(self, event, context): zappa_returndict["body"] = response.get_data(as_text=True) except UnicodeDecodeError: # If data can't be decoded as utf-8, try processing as binary + logger.warning( + "UnicodeDecodeError on response.get_data(as_text=True), " + "unable to decode response.data as 'utf8': encoding as base64 isBase64Encoded=True" + ) zappa_returndict["body"] = base64.b64encode(response.data).decode("utf8") zappa_returndict["isBase64Encoded"] = True