AWS cloud 管理控制台链接:
https://us-west-2.console.aws.amazon.com/console/home?region=us-west-2
点击控制台账户创建安全凭证
部署flask 官方指引:
http://docs.aws.amazon.com/zh_cn/elasticbeanstalk/latest/dg/create-deploy-python-flask.html
http://docs.amazonaws.cn/elasticbeanstalk/latest/dg/create-deploy-python-flask.html
tips:不翻墙有可能安装失败
mac端安装python库管理工具pip:
sudo python get-pip.py
安装 eb cli命令行工具,AWS命令行客户端:
pip install --upgrade --user awsebcli
pip install virtualenv
安装flask:
virtualenv ./eb-virtual
source ./eb-virtual/bin/activate
pip install flask==0.10.1
部署成功效果图:
示例源代码官网提供:
from flask import Flask
# print a nice greeting.
def say_hello(username = "World"):
return '<p>Hello %s!</p>\n' % username
# some bits of text for the page.
header_text = '''
<html>\n<head> <title>EB Flask Test</title> </head>\n<body>'''
instructions = '''
<p><em>Hint</em>: This is a RESTful web service! Append a username
to the URL (for example: <code>/Thelonious</code>) to say hello to
someone specific.</p>\n'''
home_link = '<p><a href="/">Back</a></p>\n'
footer_text = '</body>\n</html>'
# EB looks for an 'application' callable by default.
application = Flask(__name__)
# add a rule for the index page.
application.add_url_rule('/', 'index', (lambda: header_text +
say_hello() + instructions + footer_text))
# add a rule when the page is accessed with a name appended to the site
# URL.
application.add_url_rule('/<username>', 'hello', (lambda username:
header_text + say_hello(username) + home_link + footer_text))
# run the app.
if __name__ == "__main__":
# Setting debug to True enables debug output. This line should be
# removed before deploying a production app.
application.debug = True
application.run()
在AWS 的管理后台, 可以看到创建应用flask-env 成功: