我已经构建了一个SMS服务(使用Twilio),用户可以通过文本获取实时总线信息。目前我一直在使用ngrok在我的个人电脑上托管这个。现在我想使用AWS来托管这项服务,但我不知道应该怎么做。我试过运行一个烧瓶网络服务器并尝试让ngrok在AWS上运行,但没有运气。
这是我关于Flask和Twilio的REST Api的代码:
app = Flask(__name__)
@app.route("/sms", methods=['GET', 'POST'])
def hello_monkey():
resp = MessagingResponse()
response = request.form['Body']
if (" " in response):
response = response.split(" ")
result = look_up(response[0], response[1])
else:
result = look_up(response, False)
resp.message(result)
return str(resp)
if __name__ == "__main__":
app.run(debug=True)
在How to Send SMS Text Messages with AWS Lambda and Python 3.6的Twilio博客上有一篇博客文章。它不使用Flask,但它绝对可以修改以实现您的目标。或者,您可以阅读有关使用Flask与AWS Elastic Beanstalk here的信息。
在AWS上运行ngrok不是正确的方法。如果你想托管你自己的Flask服务器,你可以使用像Lightsail这样的东西,但这对于这种用法来说太过分了。