• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Introduction to App Engine Development
 

Introduction to App Engine Development

on

  • 2,165 views

 

Statistics

Views

Total Views
2,165
Views on SlideShare
2,165
Embed Views
0

Actions

Likes
2
Downloads
10
Comments
0

0 Embeds 0

No embeds

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

    Introduction to App Engine Development Introduction to App Engine Development Presentation Transcript

    • App EngineDevelopmentRon Reiter, 2012
    • Agenda● What is Google App Engine● Advantages● Disadvantages● Creating your first webapp● Deployment● Features● Reducing Cost
    • What is GAE● Google App Engine is a Platform-as-a- service server for web applications● Similar to Heroku, but writing atop it requires using specific Google APIs● Supports Python, Java and Go
    • Advantages● Scales automatically● Bills by services used● Easy to deploy● Extremely high uptime of all services (web server, database, cronjobs, mail delivery, etc)● Free development tier
    • Disadvantages● Cannot use native libraries with Python● Cannot use different runtime environments, such as PyPy (yet).● Constrained to Google because code is Google specific● 30 second limit per request● No websockets for now● High price because of PaaS
    • Your first Web Application● Download the Google App Engine Python SDK● Add a new application● Click "Run"● Go to http://localhost:8080● And youre done!
    • Your first Web Application● The code example contains two important files: ○ main.py - the web server code example ○ app.yaml - the web application configuration● It also contains a favicon example and a file called index.yaml, which you dont need to touch right now.
    • app.yaml● The default app.yaml configuration is to forward all requests to main.py● We will need to add a static files path, if we want App Engine to serve some static files.- url: /static static_dir: static
    • Deployment● Go to http://appengine.google.com● If you havent yet verified your account using your mobile phone, please do so● Add a new application and find an available identifier for it● Once youve created it, change your app. yaml file to use the same identifier● Using your Google credentials, Use the App Engine launcher to deploy
    • Deployment (cont.)● After deploying, use the GAE dashboard for datastore access, logs, quota details, load, and more.
    • main.pyimport webapp2class MainHandler(webapp2.RequestHandler): def get(self): self.response.write("Hello world!")app = webapp2.WSGIApplication([ (/, MainHandler)], debug=True)
    • Templatesfrom google.appengine.ext.webapp import templateimport webapp2class MainHandler(webapp2.RequestHandler): def get(self): self.response.write(template.render("index.html", { "message" : "Hello, World!" })app = webapp2.WSGIApplication([ (/, MainHandler)], debug=True)
    • GET/POST Parametersfrom google.appengine.ext.webapp import templateimport webapp2class MainHandler(webapp2.RequestHandler): def get(self): self.response.write(template.render("index.html", { "message" : self.request.get("message") })app = webapp2.WSGIApplication([ (/, MainHandler)], debug=True)
    • URL Parametersfrom google.appengine.ext.webapp import templateimport webapp2class MainHandler(webapp2.RequestHandler): def get(self, message): self.response.write(template.render("index.html", { "message" : message })app = webapp2.WSGIApplication([ (/(w+), MainHandler)], debug=True)
    • Datastore API● NoSQL Database (BigTable)● Supports an SQL-like syntax called GQL ○ GqlQuery("SELECT * FROM Song WHERE composer = : composer", composer="Lennon, John")● Scales Automatically● Django-like ORM (db.Model)● Map Reduce API● Expando - schema-less objects
    • The Model Classfrom google.appengine.ext import dbclass Post(db.Model): name = db.StringProperty() body = db.TextProperty() created = db.DateTimeProperty(auto_now_add=True)# create a new entrypost = Post( name = "Ron Reiter", body = "This is a guestbook entry!")# save it to the databasepost.put()
    • The Model Class (cont.)# get the post keypost_id = post.key().id()# using the class method to fetch the object using the IDpost = Post.get_by_id(post_id)# update the entrypost.body = "This is the updated body"post.put()
    • NDB API● An alternative to the Datastore API● Document oriented instead of column oriented● Schema-less● Can run map reduce queries on structured properties, like MongoDB
    • NDB API (cont.)class Address(ndb.Model): type = ndb.StringProperty() # E.g., home, work street = ndb.StringProperty() city = ndb.StringProperty()class Contact(ndb.Model): name = ndb.StringProperty() addresses = ndb.StructuredProperty(Address, repeated=True)guido = Contact(name=Guido, addresses=[Address(type=home, city=Amsterdam), Address(type=work, street=Spear St, city=SF)])guido.put()
    • Cloud Storage API● Cloud Storage is similar to Amazon S3● Integrates very well with App Enginewith files.open(/gs/mybucket/myobject/, r) as f: data = f.read(1) while data != "": print data data = f.read(1) print Done reading file!
    • Python Service APIs● BlobStore API - Allows saving and retrieving binary data from the datastore● Channel API - Gives server push capabilities using long polling● Memcache API - fast key/value store● LogService API - Convenient logging● Mail API - Simple email delivery● Inbound mail handler - Use request handlers to handle emails sent to the app
    • Python Service APIs● Search API - Powerful datastore search● Task Queues API - Allows queueing request handlers to process data in the background● Cron jobs - Allows scheduling request handlers to be executed● Image API - Simple image processing module, based on PIL
    • Python Service APIs● URLFetch API - Alternative to urllib, use it instead, also with asynchronous bindings● Users API - Easy integration for user authentication using Google accounts● And more...
    • Reducing Cost of GAE App● Use Go (compiled) instead of Python for CPU intensive applications● Use Asynchronous APIs to prevent spawning new handlers for no reason● Use memcache whenever possible● Reduce DataStore calls● Use cache headers
    • Questions?Thank You!