运行Flask应用程序时AWS Cloud9超时 [英] AWS cloud9 timeout when running flask application

查看:137
本文介绍了运行Flask应用程序时AWS Cloud9超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试使用flask建立一个AWS cloud9环境以开发Web应用程序。我是AWS / flask的新手,却遇到了问题。在IDE环境和在浏览器中预览应用程序之间似乎存在问题(我使用的是chrome,但也已在IE中尝试过)。

Hi all I'm trying to setup a AWS cloud9 environment with flask to develop a web app. I'm new to AWS/ flask, and stuck on an issue. There seems to be an issue between the IDE environment and previewing the application in my browser (I'm using chrome, but have also tried in IE).

来自app.py:

import os
from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello():
    return 'Hello World'


app.run(host=os.getenv('IP', '0.0.0.0'), port=int(os.getenv('PORT', 8080)))

if __name__ == '__main__':
    app.run()
    app.debug(True)

当我在终端中以root身份运行时:

When I run this in the terminal (as root):

[root@ip-172-31-11-201 environment]# python ./app.py
Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)

当我右键单击 http://0.0.0.0:8080/ 它将打开一个yab并将我重定向到公共IP xxxx:8080 并最终超时并给我:

When I right click on the on http://0.0.0.0:8080/ it will open a yab and redirect me to a Public IP x.x.x.x:8080 and will eventually timeout and give me:


err_connection_timeout

err_connection_timeout

当我尝试使用IDE运行选项运行应用程序时它将带我去:

When I attempt to run the application using the IDE run option it will take me to:

Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)

这时它也会超时。因此,这让我真的很困惑,当我在cloud9 IDE之外运行它时,我没有这个问题。我在文档中知道您应该在端口8080上指向0.0.0.0。因此,我不确定为什么使用run运行它会更改我指定的IP。

At which point it will just timeout as well. So this has me really confused, when I'm running this outside of the cloud9 IDE I don't have this issue. I know in the documentation you're supposed to point to 0.0.0.0 over port 8080. So I'm not quite sure why running that with run would change the IP I specified.

我也尝试过手动输入项目和用户名:

I've also tried manually putting my project and username in manually:


https://projectname-c9-username.c9.io/

这时它会将我重定向到一个页面,告诉我它找不到我的用户名。然后,我尝试设置一个cloud9.io帐户,该帐户已完成,我确认了我的帐户,但无法登录,仍然具有找不到用户名页面。

At which point it redirects me to a page where it tells me it "can't find my username". I then tried to setup a cloud9.io account which completed, I confirmed my account but can't login and still have the "cannot find username" page.

我在本地用cloud9测试了我的 app.py 文件,用Sublime用 0.0.0.0 替换为 127.0 .0.1 并在本地运行。

After which I tested my app.py file from cloud9 locally with sublime substituted 0.0.0.0 for 127.0.0.1 and it worked locally.

配置中是否缺少任何内容?自从AWS收购cloud9以来,设置中发生了任何更改,我一直在关注在线教程和视频,但看不到能解决这个问题。

Does is there anything I'm missing in my config? Has anything changed in the setup since AWS acquired cloud9, I've been following online tutorials and videos but just can't see to solve this issue.

来自IDE环境:

# python --version
Python 2.7.12

# pip freeze flask
astroid==1.5.3
aws-cfn-bootstrap==1.4
awscli==1.11.132
Babel==0.9.4
backports.functools-lru-cache==1.4
backports.ssl-match-hostname==3.4.0.2
boto==2.42.0
botocore==1.5.95
chardet==2.0.1
click==6.7
cloud-init==0.7.6
CodeIntel==0.9.3
colorama==0.2.5
configobj==4.7.2
configparser==3.5.0
docutils==0.11
ecdsa==0.11
enum34==1.1.6
Flask==0.12.2
futures==3.0.3
gyp==0.1
ikpdb==1.1.2
Inflector==2.0.11
iniparse==0.3.1
isort==4.2.15
itsdangerous==0.24
jedi==0.11.0
Jinja2==2.7.2
jmespath==0.9.2
jsonpatch==1.2
jsonpointer==1.0
kitchen==1.1.1
lazy-object-proxy==1.3.1
lockfile==0.8
MarkupSafe==0.11
mccabe==0.6.1
paramiko==1.15.1
parso==0.1.0
PIL==1.1.6
ply==3.4
pyasn1==0.1.7
pycrypto==2.6.1
pycurl==7.19.0
pygpgme==0.3
pyliblzma==0.5.3
pylint==1.7.4
pylint-django==0.7.2
pylint-flask==0.5
pylint-plugin-utils==0.2.6
pystache==0.5.3
python-daemon==1.5.2
python-dateutil==2.1
pyxattr==0.5.0
PyYAML==3.10
requests==1.2.3
rsa==3.4.1
simplejson==3.6.5
singledispatch==3.4.0.3
six==1.11.0
subprocess32==3.2.7
urlgrabber==3.10
urllib3==1.8.2
virtualenv==15.1.0
Werkzeug==0.13
wrapt==1.10.11
yum-metadata-parser==1.1.4
zope.cachedescriptors==4.3.0 

感谢您的帮助!

推荐答案

我通过搜索EC2问题得出了答案:

I figured out by searching EC2 questions:

您必须克服AWS防火墙/安全设置。
您必须:

You have to get past the AWS firewall / security settings. You have to:


  1. 进入EC2(从所有AWS服务列表中)

  2. 单击安全组

  3. 单击您的Cloud9实例

  4. 单击入站

  5. 单击编辑

  6. 单击添加规则

  7. 添加此规则:

  1. Go into EC2 (from the list of all AWS services)
  2. Click security groups
  3. Click your Cloud9 instance
  4. Click Inbound
  5. Click Edit
  6. Click Add Rule
  7. Add this rule:


  • 对于类型,选择定制TCP规则。 -所有流量也起作用。

  • 对于端口范围,请键入8080、8081或8082。-如果您选择了所有流量,则默认为所有端口。

  • 对于Source,选择 Anywhere,它看起来像0.0.0.0/0

以下是屏幕快照链接:< a href = https://imgur.com/a/zhQbA rel = nofollow noreferrer> https://imgur.com/a/zhQbA

Here is a screen shot link: https://imgur.com/a/zhQbA

AWS确实将其隐藏在其C9文档中。
https://docs.aws.amazon.com/cloud9/latest/user-guide/app-preview.html#app-preview-share-security-group
共享正在运行的应用程序通过Internet,第2步:为实例设置安全组

AWS does have this, buried, in their C9 documentation. https://docs.aws.amazon.com/cloud9/latest/user-guide/app-preview.html#app-preview-share-security-group In Share a Running Application over the Internet, Step 2: Set Up the Security Group for the Instance

这篇关于运行Flask应用程序时AWS Cloud9超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆