Hide
Google App Engine

3. Write to disk

This step shows that you can perform Python read and write calls to your machine's local disk. You could never do this in an App Engine app running in a sandbox, it would throw an error.

(Please note, this step is for demonstration purposes. The "local disk" is really ephemeral storage in your app's container; the disk image will be re- initialized when the VM restarts. For persistent storage you should use one of the Cloud Platform data storage products.)

Edit the main.py application file

From this point on, you won't need to change the app.yaml file.

  • Define MESSAGES, the path to a text file
  • Write the msg string to MESSAGES
  • Add a handler to display the contents of the message file
  • Link the handler to the /messages request

Test and deploy

Run locally

$ gcloud preview app run ./app.yaml

And visit http://localhost:8080/. Reload the page a few times, then try http://localhost:8080/messages.

Deploy to the cloud

$ gcloud preview app deploy ./app.yaml

Point your browser at your appspot address (http://<your-app-id>.appspot.com/). Reload the page a few times, then try http://<your-app-id>.appspot.com/messages.

Next

So you've used the built-in Python file system API. Next, you'll modify the Python standard runtime Dockerfile to include the popular Linux "fortune cookie" program.

Go to Step 4