App Engine Flashcards
What are some of the handy built in features GAE provides?
- Turn-key support for many languages
- Built-in scaling system
- Easy deployment of apps via GIT
What command do you need to run to create a new project on GAE?
gcloud app create –project=
What command do you need to run to install Python on GAE?
gcloud components install app-engine-python
What are the files needed to make an app on GAE?
- app.yaml
- requirements.txt
- main.py
What is for app.yaml file for?
General configuration file for the application
What is for requirements.txt file for?
Specifies modules/libraries to install in the environment
What is for main.py file for?
The backend application code
What command do you need to deploy your app on GAE?
gcloud app deploy
What command do you need to open your app on a new browser?
gcloud app browse
What happens to instances when your app is idle?
They get spun down
What are the ways we can implement a DB as part of our app?
- Use a file-based DB (SQLite)
- Use Datastore
- Use Google Cloud Storage
What are the cons of using a file-based DB such as SQLite
Not persistent
Every new instance starts back a 0
Why might you use a file-based DB such as SQLite
If youre working with static non changing content
What is Google Datastore?
A NoSQL Database
Deals with keys & values instead of tables & rows
What are the steps to use google datastore?
- Import it
from google.cloud import datastore - Create new Client object
datastore_client = datastore.Client()
3. Add module to requirements.txt google-cloud-datastore==2.1.6
How do you write to google datastore?
- Create entity
entity = datastore.Entity(key=myClient.key(‘hello’)) - Update entity
entity. update({‘myVal’: ‘world’}) - Write the entity back to the datastore
myClient.put(entity)
How do you fetch from google datastore?
entity = myClient.get(‘hello’)
return entity[‘myVal’] # should return ‘world’
What DB do you use to store files?
Google Cloud Storage
How does Google Cloud Storage work?
You can a bucket for your app that can be used to store and serve files your your app
What are the steps to use google cloud storage?
1. Import the module and create a client object from google.cloud import storage client = storage.Client()
- Fetch bucket ID
from google.appengine.api import app_identity
import os
buckid = os.environ.get(‘BUCKET_NAME’, app_identity.get_default_gcs_bucket_name())
How do you fetch from google cloud storage?
- Fetch bucket
bucket = client.get_bucket(buckid) - Fetch blob of data
blob = bucket.get_blob(‘/my/lovely/file.txt’) - fetch bytes from blob
data = blob.download_as_bytes()
What does the Client() function do?
Return a Client object that can be used to make subsequent calls to the Datastore
What are the 3 ways to split traffic?
- IP address
- Cookie
- Random
By default, where does google redirect traffic?
To the newest version of the app
What are the types of environment variables?
- GAE_INSTANCE
- GAE_VERSION
What does te getenv function do?
Fetches an environment variable
What does os.getenv(‘GAE_INSTANCE’) return?
The instance that we are communicating with
What does os.getenv(‘GAE_VERSION’) return?
The current version of the application that you are interfacing with
What are the 2 different environments in GAE?
- Standard
- Flexible
What are the cons of using a flexible environment?
- Can’t scale down to 0 instances
- Longer boot times
- Pricing based on compute instance characteristics