Your SlideShare is downloading. ×
Introduction to App Engine Development
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Introduction to App Engine Development


Published on

Published in: Technology

  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. App EngineDevelopmentRon Reiter, 2012
  • 2. Agenda● What is Google App Engine● Advantages● Disadvantages● Creating your first webapp● Deployment● Features● Reducing Cost
  • 3. 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
  • 4. 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
  • 5. 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
  • 6. 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!
  • 7. Your first Web Application● The code example contains two important files: ○ - 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.
  • 8. app.yaml● The default app.yaml configuration is to forward all requests to● We will need to add a static files path, if we want App Engine to serve some static files.- url: /static static_dir: static
  • 9. Deployment● Go to● 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
  • 10. Deployment (cont.)● After deploying, use the GAE dashboard for datastore access, logs, quota details, load, and more.
  • 11. main.pyimport webapp2class MainHandler(webapp2.RequestHandler): def get(self): self.response.write("Hello world!")app = webapp2.WSGIApplication([ (/, MainHandler)], debug=True)
  • 12. 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)
  • 13. 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)
  • 14. 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)
  • 15. 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
  • 16. 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()
  • 17. 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()
  • 18. 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
  • 19. 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()
  • 20. Cloud Storage API● Cloud Storage is similar to Amazon S3● Integrates very well with App Enginewith, r) as f: data = while data != "": print data data = print Done reading file!
  • 21. 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
  • 22. 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
  • 23. 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...
  • 24. 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
  • 25. Questions?Thank You!