我正在尝试将我的第一个应用程序部署到 EB,并且正在关注这个 turorial:https ://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html
不幸的是,在部署最终应用程序时,我仍然收到 502 错误。我很困惑,因为我已经按照指示去了发球台。
我收到以下错误
ImportError: Failed to find application, did you mean 'ebdjango/wsgi:application'?
Run Code Online (Sandbox Code Playgroud)
我不确定这意味着什么。根据说明,我编辑了 django.config 文件以包含以下文本:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: ebdjango/wsgi.py
Run Code Online (Sandbox Code Playgroud)
这似乎与我的文件结构相匹配:
- ebdjango
-.ebextensions
- django.config
- .elasticbeanstalk
- ebdjango
_ __init__.py
- settings.py
- urls.py
- wsgi.py
- manage.py
- requirements.txt
Run Code Online (Sandbox Code Playgroud)
所以配置文件设置正确,对吧?
我正在运行 Python 3.7 和 Django 2.2。
我知道 EB 搜索 application.py,我认为配置文件应该将服务器指向我的自定义应用程序?我在这里缺少什么?
编辑:我也收到此错误:
ModuleNotFoundError: No module named 'ebdjango/wsgi'
Run Code Online (Sandbox Code Playgroud)
我的文件结构有问题吗?
编辑 2:我忘记在我的帖子中包含init .py 文件,请参阅 Ben 的评论。
这一切都是从我下载coverage.py 并开始测试我的django 项目时开始的。一切都很好,但是我缺乏对在 Models.py 中设置的自定义用户管理器的覆盖
这是完整的代码。
模型.py
from django.contrib.auth.models import AbstractUser, BaseUserManager
from django.db import models
from django.utils.translation import ugettext_lazy as _
class UserManager(BaseUserManager):
"""Define a model manager for User model with no username field."""
use_in_migrations = True
def _create_user(self, email, password, **extra_fields):
"""Create and save a User with the given email and password."""
if not email:
raise ValueError('The given email must be set')
email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
user.set_password(password)
user.save(using=self._db)
return user
def create_user(self, email, password=None, **extra_fields): …Run Code Online (Sandbox Code Playgroud) 感谢这篇精彩的文章,我的 Django 应用程序已部署并正常工作:https://medium.com/@justaboutcloud/how-to-deploy-a-django3-application-on-elastic-beanstalk-python3-7-and-amazon- linux-2-bd9b8447b55
我已完成该项目并正在设置 HTTPS。为此,我在 .ebextensions 文件夹中创建了一个名为 02_https.config 的配置文件
在此文件中,我复制并粘贴了文章中的代码:
option_settings:
aws:elbv2:listener:443:
SSLCertificateArns: <YourACMCertificateARN>
Protocol: HTTPS
Resources:
AWSEBV2LoadBalancerListener:
Type: 'AWS::ElasticLoadBalancingV2::Listener'
Properties:
LoadBalancerArn: { "Ref" : "AWSEBV2LoadBalancer" }
DefaultActions:
- RedirectConfig:
Port: 443
Protocol: HTTPS
StatusCode: HTTP_301
Type: redirect
Port: 80
Protocol: HTTP
Run Code Online (Sandbox Code Playgroud)
当我部署应用程序时,我收到以下错误消息:
Service:AmazonCloudFormation, Message:Template format error: Unresolved resource dependencies [AWSEBV2LoadBalancer] in the Resources block of the template
Run Code Online (Sandbox Code Playgroud)
我有两个理论:
我没有以正确的格式粘贴 ARN 证书,这导致我的 YAML 格式不正确
这段代码的格式有问题。
有人可以提供一些意见吗?