Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)



Deploying the application to the cloud

Learning objectives

Prerequisites

Related

Takashi Matsuo, Jun 2012
Google Developer Relations

Introduction

This lesson teaches you how to create a Cloud SQL instance, how to access it via the command line, and how to deploy your application to the cloud.

Create and set up a Cloud SQL instance

Go to the Google APIs Console and if you don’t have any projects yet, please create your first project. Then enable Google Cloud SQL service in the ‘Services’ screen, so now you can see the 'Google Cloud SQL' menu on the left side.

Click the 'Google Cloud SQL' menu and click 'New instance...' button. Then you can see the following dialog:

New Instance popup

Probably you want to leave 'Size' and 'Pricing plan' as they are (D1 and Per use) because changing them will cost more. If you want to know more about the pricing and instance sizes, read the Cloud SQL Billing doc .

Fill in the 'Name' and 'Authorized applications' fields appropriately and click 'Create instance' button. After a few minutes, you’ll have the first Cloud SQL instance of your own. During the creation, you can see the indicator telling you it’s underway.

After the indicator disappears, click the 'SQL prompt' menu where you can execute SQL commands. As with the local MySQL instance, create a database user by executing the following commands. Enter one command at a time in the big textarea and click the 'Execute' button each time.

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON guestbook.* TO 'username'@'localhost' WITH GRANT OPTION;

Then create the 'guestbook' database with the following command:

create database guestbook charset utf8;

Select 'guestbook' database in the 'Database' select box, and create a table for our guestbook.

CREATE TABLE entries
  (id int not null auto_increment primary key,
   guest_name varchar(255),
   content varchar(255),
   created_at timestamp)
  ENGINE=InnoDB DEFAULT CHARSET=utf8;

Use command line tool to access the instance

Now you have the table in your Cloud SQL instance, so it’s ready to deploy your app to the cloud. Try using the command line tool to access your Cloud SQL instance.

App Engine SDK has a command named 'google_sql.py' which enable you to connect your Cloud SQL instance from the command line. Here is a command line example:

$ google_app_engine_sdk_path/google_sql.py instance_name guestbook

As always, replace the path and instance name with actual values. You can see your full instance name by clicking 'Instance settings' button near the top right corner of Cloud SQL screen in the API console. If it’s the first time you've run this command, a new browser window opens and starts an OAuth procedure for this command. Once you finish the OAuth procedure, you can see a 'sql>' prompt where you can execute any sql command. Play around with this command line tool a bit before going to the next section.

Deploy your application

Before deploying, add your Cloud SQL instance name to the file main.py as follows:

CLOUDSQL_INSTANCE = 'cloud_sql_instance_name'

Now, please try posting some messages on the cloud.

Lesson wrapup

Before finishing this lesson, please make sure that you understand how to:

  1. create and set up a Cloud SQL instance
  2. execute SQL command via API console and from the command line
  3. use Cloud SQL on the App Engine cloud environment

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.