英文:
How to test Flask API installed on AWS public EC2 instance?
问题
I just created a public EC2 instance on which I have imported a flask API. My goal here is to test whether the API works well or not. So I run the command python run.py
on PuTTY which results with this :
* Environment: prod
* Debug mode: off
* Running on http://127.0.0.1:5000 (Press CTRL+C to quit)
Then, I go to my windows command and I try running curl http://<EC2_public_IP>:5000/
but I get the error Failed to connect to <EC2_public_IP> port 5000 after 2159 ms: Couldn't connect to server
.
For more context, I show you the security rules on my EC2 instance :
英文:
I just created a public EC2 instance on which I have imported a flask API. My goal here is to test whether the API works well or not. So I run the command python run.py
on PuTTY which results with this :
* Environment: prod
* Debug mode: off
* Running on http://127.0.0.1:5000 (Press CTRL+C to quit)
Then, I go to my windows command and I try running curl http://<EC2_public_IP>:5000/
but I get the error Failed to connect to <EC2_public_IP> port 5000 after 2159 ms: Couldn't connect to server
.
For more context, I show you the security rules on my EC2 instance :
答案1
得分: 1
http://127.0.0.1
是一个环回地址,只能从 EC2 实例本身访问。如果您希望处理来自任何来源的流量,请将您的 Flask 运行参数更改为处理 0.0.0.0
。
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
英文:
http://127.0.0.1
is a loopback address which makes it only accessible from the EC2 instance itself, if you'd like to handle traffic from any source, please change your flask run parameter to handle 0.0.0.0
instead.
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论