是否可以将 old/legacy Django 应用程序集成到 Zappa 中以进行无服务器集成?
Is it possible to integrate an old/legacy Django application into Zappa for serverless integration?
我正在尝试找到一种方法将我们公司的 Django Web 应用程序集成到 Zappa 中,这样我们就可以使用我们的 REST API 实现完全无服务器。问题是我们的应用程序已经存在了好几年,这使得它比所有这些 Zappa 教程初始化的全新应用程序要重得多。 Zappa 是否需要一种格式来将旧的 Django 应用程序集成到其框架中?我迫不及待地想知道 Zappa 需要多少重构才能知道如何将我们的 API 转换为 lambda 函数。当我在我们的根目录中尝试 运行 Zappa deploy 时,出现以下错误,这可能意味着我们的应用程序没有针对 Zappa 系统进行优化:
Traceback (most recent call last):
File "/home/ubuntu/SkalaControl/env/lib/python3.7/site-packages/zappa/cli.py", line 896, in deploy
function_name=self.lambda_name
File "/home/ubuntu/SkalaControl/env/lib/python3.7/site-packages/zappa/core.py", line 1520, in get_lambda_function
response = self.lambda_client.get_function(FunctionName=function_name)
File "/home/ubuntu/SkalaControl/env/lib/python3.7/site-packages/botocore/client.py", line 386, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/home/ubuntu/SkalaControl/env/lib/python3.7/site-packages/botocore/client.py", line 705, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.ResourceNotFoundException: An error occurred (ResourceNotFoundException) when calling the GetFunction operation: Function not found: arn:aws:lambda:us-east-1:253119149513:function:src-dev
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ubuntu/SkalaControl/env/lib/python3.7/site-packages/zappa/cli.py", line 3422, in handle
sys.exit(cli.handle())
File "/home/ubuntu/SkalaControl/env/lib/python3.7/site-packages/zappa/cli.py", line 588, in handle
self.dispatch_command(self.command, stage)
File "/home/ubuntu/SkalaControl/env/lib/python3.7/site-packages/zappa/cli.py", line 630, in dispatch_command
self.deploy(self.vargs["zip"], self.vargs["docker_image_uri"])
File "/home/ubuntu/SkalaControl/env/lib/python3.7/site-packages/zappa/cli.py", line 930, in deploy
self.lambda_arn = self.zappa.create_lambda_function(**kwargs)
File "/home/ubuntu/SkalaControl/env/lib/python3.7/site-packages/zappa/core.py", line 1225, in create_lambda_function
response = self.lambda_client.create_function(**kwargs)
File "/home/ubuntu/SkalaControl/env/lib/python3.7/site-packages/botocore/client.py", line 386, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/home/ubuntu/SkalaControl/env/lib/python3.7/site-packages/botocore/client.py", line 705, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.InvalidParameterValueException: An error occurred (InvalidParameterValueException) when calling the CreateFunction operation: Unzipped size must be smaller than 262144000 bytes
Zappa 的主要用途之一是允许将现有的 Django 项目迁移到 AWS Lambda。因此,将您的 REST API 迁移到无服务器是 Zappa 的一个很好的用例。另外,Zappa一般都兼容老版本的Django。
您遇到的问题是AWS Lambda functions must be under 50MB compressed and 250MB uncompressed。
Zappa offers a workaround 使用 slim_handler
选项,使您的项目接近 512MB 未压缩。
要确定您当前的项目需要多少磁盘 space 未压缩,您可以 运行 以下 Zappa 命令:
zappa package <name of your environment>
并且 Zappa 将生成您的 Django 项目的 zip 文件。然后您可以解压缩 zip 文件并确定磁盘 space 要求。
如果您需要超过 512MB 的磁盘 space,那么您唯一的选择是使用 AWS Lambda Container Image Support feature that was introduced recently (at least when this answer was written). Zappa version 0.53.0 supports this feature. Instructions on how to leverage this are not yet in the Zappa documentation so the best guide right now can be found at Ian Whitestone's blog。
关于 AWS Lambda 和 'heaviness' 现有 Django 应用程序的性能主题。将 Django 应用程序置于 AWS Lambda 环境中就像在汽车中安装更大的引擎。您可能会发现您的 Django 应用程序在 AWS 中的性能 更好。
我正在尝试找到一种方法将我们公司的 Django Web 应用程序集成到 Zappa 中,这样我们就可以使用我们的 REST API 实现完全无服务器。问题是我们的应用程序已经存在了好几年,这使得它比所有这些 Zappa 教程初始化的全新应用程序要重得多。 Zappa 是否需要一种格式来将旧的 Django 应用程序集成到其框架中?我迫不及待地想知道 Zappa 需要多少重构才能知道如何将我们的 API 转换为 lambda 函数。当我在我们的根目录中尝试 运行 Zappa deploy 时,出现以下错误,这可能意味着我们的应用程序没有针对 Zappa 系统进行优化:
Traceback (most recent call last):
File "/home/ubuntu/SkalaControl/env/lib/python3.7/site-packages/zappa/cli.py", line 896, in deploy
function_name=self.lambda_name
File "/home/ubuntu/SkalaControl/env/lib/python3.7/site-packages/zappa/core.py", line 1520, in get_lambda_function
response = self.lambda_client.get_function(FunctionName=function_name)
File "/home/ubuntu/SkalaControl/env/lib/python3.7/site-packages/botocore/client.py", line 386, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/home/ubuntu/SkalaControl/env/lib/python3.7/site-packages/botocore/client.py", line 705, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.ResourceNotFoundException: An error occurred (ResourceNotFoundException) when calling the GetFunction operation: Function not found: arn:aws:lambda:us-east-1:253119149513:function:src-dev
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ubuntu/SkalaControl/env/lib/python3.7/site-packages/zappa/cli.py", line 3422, in handle
sys.exit(cli.handle())
File "/home/ubuntu/SkalaControl/env/lib/python3.7/site-packages/zappa/cli.py", line 588, in handle
self.dispatch_command(self.command, stage)
File "/home/ubuntu/SkalaControl/env/lib/python3.7/site-packages/zappa/cli.py", line 630, in dispatch_command
self.deploy(self.vargs["zip"], self.vargs["docker_image_uri"])
File "/home/ubuntu/SkalaControl/env/lib/python3.7/site-packages/zappa/cli.py", line 930, in deploy
self.lambda_arn = self.zappa.create_lambda_function(**kwargs)
File "/home/ubuntu/SkalaControl/env/lib/python3.7/site-packages/zappa/core.py", line 1225, in create_lambda_function
response = self.lambda_client.create_function(**kwargs)
File "/home/ubuntu/SkalaControl/env/lib/python3.7/site-packages/botocore/client.py", line 386, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/home/ubuntu/SkalaControl/env/lib/python3.7/site-packages/botocore/client.py", line 705, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.InvalidParameterValueException: An error occurred (InvalidParameterValueException) when calling the CreateFunction operation: Unzipped size must be smaller than 262144000 bytes
Zappa 的主要用途之一是允许将现有的 Django 项目迁移到 AWS Lambda。因此,将您的 REST API 迁移到无服务器是 Zappa 的一个很好的用例。另外,Zappa一般都兼容老版本的Django。
您遇到的问题是AWS Lambda functions must be under 50MB compressed and 250MB uncompressed。
Zappa offers a workaround 使用 slim_handler
选项,使您的项目接近 512MB 未压缩。
要确定您当前的项目需要多少磁盘 space 未压缩,您可以 运行 以下 Zappa 命令:
zappa package <name of your environment>
并且 Zappa 将生成您的 Django 项目的 zip 文件。然后您可以解压缩 zip 文件并确定磁盘 space 要求。
如果您需要超过 512MB 的磁盘 space,那么您唯一的选择是使用 AWS Lambda Container Image Support feature that was introduced recently (at least when this answer was written). Zappa version 0.53.0 supports this feature. Instructions on how to leverage this are not yet in the Zappa documentation so the best guide right now can be found at Ian Whitestone's blog。
关于 AWS Lambda 和 'heaviness' 现有 Django 应用程序的性能主题。将 Django 应用程序置于 AWS Lambda 环境中就像在汽车中安装更大的引擎。您可能会发现您的 Django 应用程序在 AWS 中的性能 更好。