Intro: I am deploying a django app to AWS lambda severlessly using zappa. My RDS instance has a postgres database. I am watching rich jones djangocon video on how to deploy django app severlessly using zappa. So far I have managed to reach the part where I need to add a database to my project. I have already done pip install zappa-django-utils
and added it to my INSTALLED_APPS
. Now when I try to run
zappa manage create_pg_db production
I get the error:
Error: Please define stage 'create_pg_db' in your Zappa settings.
I even tried zappa manage create_pg_db
I am still getting the same error
Below is how my zappa_settings.json file looks:
{
"production": {
"aws_region": "us-east-1",
"django_settings": "Cool.settings",
"profile_name": "default",
"project_name": "cool",
"runtime": "python3.6",
"s3_bucket": "cool-7dsfsdf5",
"project_directory": "/tmp/code",
"slim_handler": true,
"vpc config": {
"SubnetIds": [
"subnet-3132ss13b",
"subnet-321321319",
"subnet-2c2313223",
"subnet-5ljlkjljd",
"subnet-132121357",
"subnet-f925f9c7"
],
"SecurityGroupIds": [
"sg-a9asdasd"
]
}
},
"production_ap_northeast_1": {
"aws_region": "ap-northeast-1",
"extends": "production"
},
"production_ap_northeast_2": {
"aws_region": "ap-northeast-2",
"extends": "production"
},
... All regions..
}
How do I define stage create_pg_db
in your Zappa settings. Does anyone know the steps ahead of this.
Results with zappa manage production create_pg_db
(Venv) $ django-admin --version
1.11.15
(Venv) $ zappa manage production create_pg_db
[START] RequestId: c621321b9-611d-4457-9c23-f65465653dd Version: $LATEST
[DEBUG] 2019-01-28T04:55:05.629Z c6231b9-611d-4457-9c23-f6064654653dd Zappa Event: {'manage': 'create_pg_db'}
No module named 'django': ModuleNotFoundError
Traceback (most recent call last):
File "/var/task/handler.py", line 580, in lambda_handler
return LambdaHandler.lambda_handler(event, context)
File "/var/task/handler.py", line 248, in lambda_handler
return handler.handler(event, context)
File "/var/task/handler.py", line 399, in handler
from django.core import management
ModuleNotFoundError: No module named 'django'
[END] RequestId: c621321b9-611d-4457-9c23-f65465653dd
[REPORT] RequestId: c621321b9-611d-4457-9c23-f65465653dd
Duration: 1.85 ms
Billed Duration: 100 ms
Memory Size: 512 MB
Max Memory Used: 512 MB
Error: Unhandled error occurred while invoking command.
You only have one stage defined which is called production. If you want to name your stage create_pg_db then it would like this:
{
"create_pg_db": {
"aws_region": "us-east-1",
"django_settings": "Cool.settings",
"profile_name": "default",
"project_name": "cool",
"runtime": "python3.6",
"s3_bucket": "cool-7dsfsdf5",
"project_directory": "/tmp/code",
"slim_handler": true,
"vpc config": {
"SubnetIds": [
"subnet-3132ss13b",
"subnet-321321319",
"subnet-2c2313223",
"subnet-5ljlkjljd",
"subnet-132121357",
"subnet-f925f9c7"
],
"SecurityGroupIds": [
"sg-a9asdasd"
]
}
},
"production_ap_northeast_1": {
"aws_region": "ap-northeast-1",
"extends": "production"
},
"production_ap_northeast_2": {
"aws_region": "ap-northeast-2",
"extends": "production"
},
... All regions...
"production": {
"aws_region": "us-east-1",
"django_settings": "Cool.settings"
... MORE settings...
}
At the end you can add more stages and then use the stage for your deployment. For example, you can have a develop stage that deploys your code to a development environment and a production stage that deploys your code to the production environment.