简介:我正在使用zappa毫不费力地将django应用程序部署到AWS lambda。我的RDS实例有一个postgres数据库。我正在观看rich jones djangocon video,了解如何使用zappa大力部署django应用。到目前为止,我已经设法达到需要在项目中添加数据库的部分。我已经完成pip install zappa-django-utils
并将其添加到我的INSTALLED_APPS
中。现在,当我尝试运行
zappa manage create_pg_db production
我收到错误:
Error: Please define stage 'create_pg_db' in your Zappa settings.
我什至尝试zappa manage create_pg_db
仍然遇到相同的错误
以下是我的zappa_settings.json文件的外观:
{
"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..
}
如何在Zappa设置中定义阶段create_pg_db
。有谁知道前面的步骤。
结果 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.
答案 0 :(得分:1)
您仅定义了一个阶段,称为生产。如果要命名舞台 create_pg_db ,则需要这样:
{
"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...
}
最后,您可以添加更多阶段,然后将其用于部署。例如,您可以具有一个 develop 阶段,该阶段将代码部署到开发环境中;而 production 阶段,将代码部署到生产环境中。