2

简介:我正在使用 zappa 将 django 应用程序部署到 AWS lambda。我的 RDS 实例有一个 postgres 数据库。我正在观看关于如何使用 zappa 无条件部署 django 应用程序的丰富 jones djangocon 视频。到目前为止,我已经成功地达到了需要向我的项目中添加数据库的部分。我已经完成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..
}

如何create_pg_db在 Zappa 设置中定义阶段。有谁知道这之前的步骤。

结果与 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.
4

1 回答 1

3

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

最后,您可以添加更多阶段,然后使用该阶段进行部署。例如,您可以有一个将代码部署到开发环境的开发阶段和一个将代码部署到生产环境的生产阶段。

于 2019-06-18T11:34:04.213 回答