Error: Please define stage 'create_pg_db' in your Zappa settings

Error: Please define stage 'create_pg_db' in your Zappa settings

简介: 我正在使用 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.

您只定义了一个阶段,称为 生产。如果你想命名你的舞台 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 阶段。