Monday, November 12, 2012

Started to use Google App Engine !

Today I did some readings about Google App Engine and started learning to develop applications for it. There are three languages supported in the Google App Engine which are Python, Java and Go. Since I'm a Python lover, I directly moved in to learn about what I can do with Python on Google App Engine.

There are lot of resources available in the web and therefore it is not a necessary to write about it. So I'm directly writing down what are the things I learned today by exploring Google App Engine. First of all I downloaded the Google App Engine SDK from here. Since I'm using Linux, I downloaded the version for the Linux platform which comes as a Zipped archive.

After uncompressing the Zipped folder, we can see different Python based tools available on this source code. So, now I'm writing a simple program which prints some text on the web browser.

1) Create a new directory in some where in the file system. Say we created it in desktop naming as my-application.

mkdir my-application

2. Now create a file named as app.yaml inside that directory and add the following content to it. Please note that application name is given as my-application. You have to give a unique name for this application.

 application: my-application  
 version: 1  
 runtime: python27  
 api_version: 1  
 threadsafe: yes  
 - url: .*  
 - name: webapp2  
  version: "2.5.1"  

3. Now create another file named as which will contain the codes of our application. Add the following content to that file.

 #!/usr/bin/env python  
 import cgi  
 import datetime  
 import webapp2  
 class MainPage(webapp2.RequestHandler):  
  def get(self):  
           self.response.out.write('<html><body><h4>My First Google App Engine Application</h4>')  
 app = webapp2.WSGIApplication([  
  ('/', MainPage)  
 ], debug=True)  

4. Now our source codes are ready. We have to test this app. Google App Engine SDK comes with a server which can be used to test our application before actually deploying the application on Google cloud. To use this server, go into the uncompressed Google App Engine SDK source folder. There's a tool named as Run this python script giving the path to our new application as follows.

python /path/to/my-application

Then this server will start. Now open a web browser and go to the following URL.


The text "My First Google App Engine Application" will be printed on the browser. That means our application is ready.

5. Now we can try deploying our simple app on the Google cloud. To do that we have to go to the this URL ( and sign in. Then click on the "Create Application" button. As the application identifier you have to give a unique name for the application. This name should be defined as the application name in app.yaml file. For example we might use my-application as the name if nobody has used that name for an application on Google App Engine.

The give some Application title and then click on "Create Application" button. Now google is ready to host our application.

6. To upload our application codes to the Google cloud, we can use tool which also came with the Google App Engine SDK. We run it giving the path to our application as follows.

python update /path/to/my-application

After this tool completes running your application is gone to the Google cloud. You can see it from the domain name with the application name in front of it. For example if the application name is my-application then you can access your app by typing the following URL on the web browsers address bar.
If every thing is fine, you will see the text "My First Google App Engine Application" on the web browser again.

1 comment: