GCP
Google Cloud Fundamentals
Getting started with App Engine

Getting started with App Engine

We will build a python app with App Engine Memcache to store entries ephemerally.

Memcache is not persistent storage - it is cached storage useful for speeding up requests, and also reduces infrastructure costs on App Engine.

We will:

  1. we will clone the app using an existing compute instance
  2. deploy our app via the instance
  3. view the cached data

Start a VM instance and clone the app

Start the compute instance created in #9:

  1. visit Compute Engine (opens in a new tab)

  2. start the instance

  3. open Cloud Shell (SDK is always the latest, as opposed to when SDK is run locally)

  4. ssh onto our instance

    $ glcoud compute ssh <instance-name>
  5. clone the app

    $ git clone https://github.com/GoogleCloudPlatformTraining/cp100-appengine-memcache-python.git
    $ cd cp100-appengine-memcache-python

Deploy the app

The app is comprised of 3 main files:

  • guestbook.py
    • the backend of the application
  • index.html
    • data passed to index.html via the jinja templating engine imported in our application
  • app.yaml

Our app.yaml looks like this:

# application is the project id in GAE
# this will be removed and a project id specified when running the deploy command
application: your-app-id
# the version of your app
# this is automatically generated, or specified via the deploy command, and so 
# will also be removed
version: 1
runtime: python27
api_version: 1
threadsafe: true
  version: latest
 
# routing rules
handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico
 
- url: /.*
  script: guestbook.application
 
 
libraries:
# webapp2 handles requests to the application
- name: webapp2
  version: latest
# jinja2 is responsible for templating
- name: jinja2
  version: latest

To deploy the app:

  1. remove application and version from app.yaml

  2. run the deploy command

    # deploy our app
    $ gcloud app deploy app.yaml --project <project-id>
  3. when the command succeeds we can get the URL to view our app using gcloud:

    $ gcloud app browse --project=<project-id>
    <project-id>.appspot.com
  4. at App Engine (opens in a new tab) we can see that we have an app running, and can access it via the URL in the to-right of the logging area

  5. at GAE Versions (opens in a new tab) we can see current version running, and also access the app from its line item

  6. We can add cached data to the app, and see the requests logged on our app dashboard

  7. At GAE Memcache (opens in a new tab) we can see how many times there has been a cache hit. Refreshing the app will increment the hits count on this page.

  8. At GAE Instances (opens in a new tab) we can see the total number of requests on our application

  9. Under Logging (opens in a new tab), once selecting 'GAE Application' from the dropdown, we can see details of all requests

  10. We can view the cached data in Memcache (opens in a new tab):

    1. click 'Find a key'
    2. select 'Python string' from 'Key type'
    3. use 'entries' in 'key'
    4. click 'Find'
    5. click 'entries' in the table that comes back with the response
    6. look at the fine entries stored in Memcache

Deploy a new version

  1. change the HTML file so that the difference can be seen

  2. deploy the app with a new version

    $ gcloud app deploy app.yaml --project <project-id> --version 2
  3. under GAE Versions (opens in a new tab) we can see our new version. The previous version now has a different URL, with the latest version having the original URL

  4. we can set traffic splitting to split traffic between multiple versions here, too

  5. on the dashboard we can see metrics for specific version using the 'version' select menu

Cleanup

  1. GAE instance doesn't need to be stopped, as usage limits are generous
  2. Make sure to stop the compute instance used to deploy the app