如何测试安装在AWS公共EC2实例上的Flask API?

huangapple go评论61阅读模式
英文:

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 :
如何测试安装在AWS公共EC2实例上的Flask API?

英文:

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://&lt;EC2_public_IP&gt;:5000/ but I get the error Failed to connect to &lt;EC2_public_IP&gt; port 5000 after 2159 ms: Couldn&#39;t connect to server.

For more context, I show you the security rules on my EC2 instance :
如何测试安装在AWS公共EC2实例上的Flask API?

答案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__ == &#39;__main__&#39;:
    app.run(host=&#39;0.0.0.0&#39;, port=5000)

huangapple
  • 本文由 发表于 2023年6月29日 23:13:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76582392.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定