为什么在AWS上将Flask应用程序上载到Elastic Beanstalk时会出现此错误?

2024-06-26 00:05:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将我的Flask REST服务应用程序上载到AWS Elastic Beanstalk(这是第一次),当我eb create时,我得到以下输出:

Creating application version archive "app-ef62-200423_114608".
Uploading crunchtime/app-ef62-200423_114608.zip to S3. This may take a while.
Upload Complete.
Environment details for: crunchtime-dev2
  Application name: crunchtime
  Region: us-east-1
  Deployed Version: app-ef62-200423_114608
  Environment ID: e-tmnvmkbmbm
  Platform: arn:aws:elasticbeanstalk:us-east-1::platform/Python 3.7 running on 64bit Amazon Linux 2/3.0.0
  Tier: WebServer-Standard-1.0
  CNAME: crunchtime-dev2.us-east-1.elasticbeanstalk.com
  Updated: 2020-04-23 16:46:12.577000+00:00
Printing Status:
2020-04-23 16:46:11    INFO    createEnvironment is starting.
2020-04-23 16:46:12    INFO    Using elasticbeanstalk-us-east-1-046059243220 as Amazon S3 storage bucket for environment data.
2020-04-23 16:46:34    INFO    Created target group named: arn:aws:elasticloadbalancing:us-east-1:046059243220:targetgroup/awseb-AWSEB-1MA4IAAU8730S/44d40acdd42fb6fa
2020-04-23 16:46:34    INFO    Created security group named: sg-050734e1b49a45778
2020-04-23 16:46:49    INFO    Created security group named: awseb-e-tmnvmkbmbm-stack-AWSEBSecurityGroup-BNLNN14GCIVO
2020-04-23 16:46:49    INFO    Created Auto Scaling launch configuration named: awseb-e-tmnvmkbmbm-stack-AWSEBAutoScalingLaunchConfiguration-17QIO7WCEKLK
2020-04-23 16:47:51    INFO    Created Auto Scaling group named: awseb-e-tmnvmkbmbm-stack-AWSEBAutoScalingGroup-1AUHYUG14UP16
2020-04-23 16:47:51    INFO    Waiting for EC2 instances to launch. This may take a few minutes.
2020-04-23 16:48:06    INFO    Created Auto Scaling group policy named: arn:aws:autoscaling:us-east-1:046059243220:scalingPolicy:c87fb50f-412c-48be-8b86-3fdb0c5941cc:autoScalingGroupName/awseb-e-tmnvmkbmbm-stack-AWSEBAutoScalingGroup-1AUHYUG14UP16:policyName/awseb-e-tmnvmkbmbm-stack-AWSEBAutoScalingScaleUpPolicy-4ZFDFHPU2G5H
2020-04-23 16:48:07    INFO    Created Auto Scaling group policy named: arn:aws:autoscaling:us-east-1:046059243220:scalingPolicy:b989a6ea-e4da-4b72-ae95-d63d045d4e70:autoScalingGroupName/awseb-e-tmnvmkbmbm-stack-AWSEBAutoScalingGroup-1AUHYUG14UP16:policyName/awseb-e-tmnvmkbmbm-stack-AWSEBAutoScalingScaleDownPolicy-ZX79COIXDDM8
2020-04-23 16:48:07    INFO    Created CloudWatch alarm named: awseb-e-tmnvmkbmbm-stack-AWSEBCloudwatchAlarmHigh-1AYVN9U2HYR6B
2020-04-23 16:48:07    INFO    Created CloudWatch alarm named: awseb-e-tmnvmkbmbm-stack-AWSEBCloudwatchAlarmLow-NFZ51TH8BXXG
2020-04-23 16:49:41    INFO    Created load balancer named: arn:aws:elasticloadbalancing:us-east-1:046059243220:loadbalancer/app/awseb-AWSEB-1WW6C7M7P6W7Y/bbd89b5ee56cefb5
2020-04-23 16:49:57    INFO    Created Load Balancer listener named: arn:aws:elasticloadbalancing:us-east-1:046059243220:listener/app/awseb-AWSEB-1WW6C7M7P6W7Y/bbd89b5ee56cefb5/4cf5978d2b57402f
**2020-04-23 16:50:59    ERROR   [Instance: i-013f4f7a5ee8b4c9b] Command failed on instance. An unexpected error has occurred [ErrorCode: 0000000001].**
2020-04-23 16:50:59    INFO    Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
**2020-04-23 16:52:03    ERROR   Create environment operation is complete, but with errors. For more information, see troubleshooting documentation.**

ERROR: ServiceError - Create environment operation is complete, but with errors. For more information, see troubleshooting documentation.

eb health给出了以下输出:

WebServer                                                                                                   Python 3.7 running on 64bit Amazon Linux 2/3.0.0  total      ok    warning  degraded  severe    info   pending  unknown 
    1        0        0        0        1        0        0        0    

  instance-id           status     cause                                                                                                            health  
    Overall             Severe     Command failed on all instances.                                                                                                                            Incorrect application version found on all instances. Expected version "app-ef62-200423_014023" (deployment 1).                                             ELB processes are not healthy on all instances.                                                                                                             ELB health is failing or not available for all instances.                                                                  i-07fcd462c512ebd70   Severe     Application deployment failed at 2020-04-23T06:49:51Z with exit status 1 and error: Engine execution has encountered an e                                   Incorrect application version "app-ef62-200423_014904" (deployment 2). Expected version "app-ef62-200423_014023" (deploym                                   Process default has been unhealthy for 10 hours (Target.ResponseCodeMismatch).                                              

eb status --verbose给出了以下内容:

Environment details for: crunchtime-dev
  Application name: crunchtime
  Region: us-east-1
  Deployed Version: app-ef62-200423_014023
  Environment ID: e-pxhhwgvphn
  Platform: arn:aws:elasticbeanstalk:us-east-1::platform/Python 3.7 running on 64bit Amazon Linux 2/3.0.0
  Tier: WebServer-Standard-1.0
  CNAME: crunchtime-dev.us-east-1.elasticbeanstalk.com
  Updated: 2020-04-23 06:49:55.463000+00:00
  Status: Ready
  Health: Red
  Running instances: 1
           i-07fcd462c512ebd70: unhealthy
                Description: Health checks failed with these codes: [502]
                Reason: Target.ResponseCodeMismatch

我在这个应用程序中使用Pipenv,起初我认为这是因为我使用的是这个Pipfile,而不是requirements.txt,但这篇文章似乎表明,只要我使用的是Amazon Linux 2,我就可以使用Pipenv。(在64位Amazon Linux 2上运行的Python 3.7)

以下是我的PIP文件的内容:

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
pylint = "*"
flake8 = "*"
autopep8 = "*"
rope = "*"

[packages]
flask = "*"
flask-restful = "*"
marshmallow = "*"
flask-marshmallow = "*"
flask-sqlalchemy = "*"
marshmallow-sqlalchemy = "*"
flask-migrate = "*"
flask-script = "*"
psycopg2-binary = "*"
python-dotenv = "*"
bcrypt = "*"
pyjwt = "*"
flask-cors = "*"
exponent-server-sdk = "*"
flask-apscheduler = "*"

[requires]
python_version = "3.7"

[scripts]
dev = "python application.py"
initdb = "python migrate.py db init"
migrate = "python migrate.py db migrate"
upgrade = "python migrate.py db upgrade"
downgrade = "python migrate.py db downgrade"

Tags: infoawsappflaskstackonnamedarn