• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
TLS303 How to Deploy Python Applications on AWS Elastic Beanstalk - AWS re:Invent 2012
 

TLS303 How to Deploy Python Applications on AWS Elastic Beanstalk - AWS re:Invent 2012

on

  • 3,909 views

 

Statistics

Views

Total Views
3,909
Views on SlideShare
3,903
Embed Views
6

Actions

Likes
8
Downloads
0
Comments
0

1 Embed 6

https://www.rebelmouse.com 6

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    TLS303 How to Deploy Python Applications on AWS Elastic Beanstalk - AWS re:Invent 2012 TLS303 How to Deploy Python Applications on AWS Elastic Beanstalk - AWS re:Invent 2012 Presentation Transcript

    • Availability Zone Security GroupAuto scaling Group
    • Security Group Production Availability Zone Security Group Staging Availability ZoneAuto scaling Group Auto scaling Group Security Group Integration Availability Zone Development Security Group Availability Zone Auto scaling Group Auto scaling Group
    • Deployment is Hard
    • AWS Elastic Beanstalk
    • Amazon DynamoDB Application
    • $ curl tnee.us/api/v1/shorten?url=http://aws.amazon.com/{ "shorturl": "http://tnee.us/eeGdAO"}$ curl http://tnee.us/eeGdAOHTTP/1.0 301 MOVED PERMANENTLYContent-Type: text/html; charset=utf-8Content-Length: 251Location: http://aws.amazon.com/
    • pip installs python packagesvirtualenv isolates python packagesgit stores revisions of our appeb manages our deployed application
    • pip installs python packages$ pip install flask$ python -c "import flask; print flask"<module flask from/usr/local/lib/python/…/flask/__init__.pyc>
    • pip installs python packages$ pip install flask$ python -c "import flask; print flask"<module flask from/usr/local/lib/python/…/flask/__init__.pyc>
    • virtualenv isolates python packagesvenv1 venv2./venv1/lib/python ./venv2/lib/python./venv1/bin/python ./venv2/bin/python
    • virtualenv isolates python packages $ virtualenv venv1 $ . venv1/bin/activate $ which python venv1/bin/python $ pip install flask $ python -c "import flask; print flask” <module flask from ./venv1/lib/python/.../flask/__init__.pyc>
    • ├── application.py├── requirements.txt├── scripts│ └── createtable.py├── shortflask│ ├── __init__.py│ ├── views.py│ ├── config.py│ ├── db.py│ └── shortener.py└── tests
    • application.pyimport shortflaskapplication = shortflask.create_app()if __name__ == __main__: application.run(debug=True)
    • requirements.txtFlask==0.9Jinja2==2.6Werkzeug==0.8.3boto==2.6.0
    • requirements.txtFlask==0.9 pip install flask botoJinja2==2.6 pip freeze > requirements.txtWerkzeug==0.8.3boto==2.6.0
    • shortflask/views.py@app.route(/api/v1/shorten, methods=[GET])def create_shortened_url(): url = request.args[url] host = request.headers[Host] try: shortened = _shorten_url(url) except Exception, e: return "Unable to shorten url.", 500 return jsonify({ shorturl: http://%s/%s % (host, shortened)})
    • What have we NOT done?
    • CurrentApache Sample Appwsgi.conf
    • CurrentApache Sample Appwsgi.conf Our Application
    • CurrentApache Sample App venv pipwsgi.conf Our Application
    • CurrentApache Sample App venv pip generatewsgi.conf Our Application
    • Apache Sample App Current venv pipwsgi.conf Our Application
    • One Hour10 threads 15 urls 10 instances
    • .elasticbeanstalk/optionsettings[aws:autoscaling:trigger]MeasureName = CPUUtilizationUpperThreshold = 90LowerThreshold = 40Unit = Percent
    • 515,656135,0911 Instance 4 Instances with Auto Scaling
    • djangoimg/wsgi.pyimport osos.environ.setdefault( "DJANGO_SETTINGS_MODULE", "djangoimg.settings")from django.core.wsgi import get_wsgi_applicationapplication = get_wsgi_application()
    • djangoimg/settings.pyINSTALLED_APPS = ( ... south, storages, easy_thumbnails, imgshare,)
    • djangoimg/settings.pySTATIC_ROOT = os.path.join( os.path.dirname( os.path.dirname( os.path.abspath(__file__))), static)STATIC_URL = /static/
    • djangoimg/settings.pyAWS_ACCESS_KEY_ID = os.environ.get(ACCESS_KEY)AWS_SECRET_ACCESS_KEY = os.environ.get(SECRET_KEY)DEFAULT_FILE_STORAGE = storages.backends.s3boto.S3BotoStorageAWS_STORAGE_BUCKET_NAME = djangoimgMEDIA_URL = (http://%s.s3.amazonaws.com/ % AWS_STORAGE_BUCKET_NAME)
    • .ebextensions/python.configcommands: 01_syncdb: command: "django-admin.py syncdb --noinput" leader_only: true 02_migrate: command: "django-admin.py migrate" leader_only: true 03_collectstatic: command: "django-admin.py collectstatic --noinput"
    • .ebextensions/python.configoption_settings: "aws:elasticbeanstalk:container:python:environment": DJANGO_SETTINGS_MODULE: "djangoimg.settings" "aws:elasticbeanstalk:container:python": WSGIPath: "djangoimg/wsgi.py" "aws:elasticbeanstalk:container:python:staticfiles": "/static/": "static/"
    • ApplicationElastic Beanstalk Envi r onment
    • RDS Create ApplicationElastic Beanstalk Envi r onment
    • RDS Authorize Create ApplicationElastic Beanstalk Envi r onment
    • RDS Authorize Create ApplicationElastic Beanstalk Envi r onment Inject RDS_DB_NAME RDS_USERNAME RDS_PASSWORD RDS_HOSTNAME RDS_PORT
    • djangoimg/settings.pyif RDS_HOSTNAME in os.environ: DATABASES = { default: { ENGINE: django.db.backends.mysql, NAME: os.environ[RDS_DB_NAME’], USER: os.environ[RDS_USERNAME], PASSWORD: os.environ[RDS_PASSWORD], HOST: os.environ[RDS_HOSTNAME], PORT: os.environ[RDS_PORT], } }
    • We are sincerely eager to hear your feedback on thispresentation and on re:Invent. Please fill out an evaluation form when you have a chance.