I am trying to find a way to integrate our company's Django Web app into Zappa so we can go completely serverless with our REST API. The problem is that our app has existed for several years, making it a lot heavier than the brand new apps that all of these Zappa tutorials init over. Is there a format that Zappa requires for integrating an old Django app into its framework? I have no wait of knowing how much refactoring will be required for Zappa to know how to transition our API into lambda functions. When I tried running Zappa deploy in our root directory, I got the following error, which probably means our app is poorly optimized for the Zappa system:
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
One of the primary uses of Zappa is to allow the migration of an existing Django project into AWS Lambda. So moving your REST API to be serverless is an excellent use case for Zappa. In addition, Zappa generally is compatible with older versions of Django.
The issue you are encountering is that AWS Lambda functions must be under 50MB compressed and 250MB uncompressed.
Zappa offers a workaround using the slim_handler
option that allows your project to approach 512MB uncompressed.
To determine how much disk space your current project requires uncompressed, you may run the following Zappa command:
zappa package <name of your environment>
And Zappa will generate a zip file of your Django project. Then you can uncompress the zip file and determine the disk space requirements.
If you require more than 512MB of disk space, then your only option is to use the 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.
On the topic of performance for AWS Lambda and 'heaviness' of an existing Django application. Putting your Django app in AWS Lambda environment is like installing a bigger engine in a car. You may find that your Django applications perform better in AWS.