http://docs.aws.amazon.com/ja_jp/elasticbeanstalk/latest/dg/create-deploy-python-flask.html I will work along with
[AWS] I tried to build a Python environment with eb Development environment is at least in an environment where it can be done.
In short, it is OK if you can use the following 4
Work with my client (I'm a Mac)
variable
VIRTUAL_ENV_NAME='eb-test-Flask'
command
VIRTUAL_ENV_NAME='eb-test-Flask'
cd ~
virtualenv ${VIRTUAL_ENV_NAME}
result
New python executable in /Users/****/eb-test-Flask/bin/python
Installing setuptools, pip, wheel...done.
command
source ~/${VIRTUAL_ENV_NAME}/bin/activate
OK if the environment name is attached at the beginning of the command prompt with ()
Verification
(eb-test-Flask)
command
pip install flask==0.10.1
Verification
pip freeze
result
Flask==0.10.1
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
Werkzeug==0.11.9
If the above result is output, it is successful.
Next, create an application to deploy using Elastic Beanstalk. Here we will create a RESTful web service called "Hello World".
Verification The environment name must be in parentheses at the beginning of the command prompt. With this procedure (eb-test-Flask)
Verification
pwd
result
/Users/****/eb-test-Flask
variable
PJ_DIR_NAME='eb-flask'
command
mkdir ${PJ_DIR_NAME}
Verification
ls | grep ${PJ_DIR_NAME}
result
eb-flask
command
cd ${PJ_DIR_NAME}
Verification
pwd
result
/Users/****/eb-test-Flask/eb-flask
Create a sample application The code is excerpted from the documentation and used as is
application.py
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()
Make sure you are in the working directory under the virtual environment. (If you haven't done anything else from the process so far, it's okay)
Verification
pwd
result
/Users/****/eb-test-Flask/eb-flask
command
python application.py
result
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger pin code: 344-661-719
Launch your browser Go to http://127.0.0.1:5000/.
Verification
curl http://127.0.0.1:5000/
result
<html>
<head> <title>EB Flask Test</title> </head>
<body><p>Hello World!</p>
<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>
</body>
If you can confirm it, you can stop it.
command
Control + C
Since the application was able to run in my environment, I will implement it in eb
Caution I will continue to work in a virtual environment
command
cd ~/${VIRTUAL_ENV_NAME}/${PJ_DIR_NAME}
pwd
result
/Users/****/eb-test-Flask/eb-flask
command
pip freeze > requirements.txt
Verification
cat requirements.txt
result
Flask==0.10.1
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
Werkzeug==0.11.9
Elastic Beanstalk uses requirements.txt to determine which packages to install on the EC2 instance that runs your application.
So this work is necessary. And the file name must also be requirements.txt.
command
deactivate
It's okay if the () at the beginning of the prompt disappears
Verification
tree ~/${VIRTUAL_ENV_NAME}/${PJ_DIR_NAME}
result
/Users/****/eb-test-Flask/eb-flask/
├── application.py
└── requirements.txt
Flask application deployment that tried to build Python environment with eb
Recommended Posts