Hello world on Google App Engine

Google App Engine
Google Cloud Platform
It takes me ages and a load of frustration to get Hello World to work on Google App Engine
Published

November 28, 2024

I succeeded, but it was very annoying

I managed to get my hello world program working after a lot of messing about. Some of the issues were due to the terribly designed interfaces to Google services, and some of it was just my lack of experience using them.

Aim

I want to experiment with making an online Python App with Google App Engine. The first step is to understand how Google App Engine works, and to do that I’ll do the minimum possible — a web app that displays “Hello world!”.

Costs

To use Google App Engine you have to sign up with a bank card. But the free tier is very generous:

The Google Cloud Free Tier is available only for the Standard Environment, but that’s what I want to use so no problem. I doubt I’ll get anywhere close to the free their usage limits, but to be on the safe side (I’m a bit paranoid about this type of thing) I will see how to configure daily budget limits.

Sign-up and setting-up process

Of course I already have personal and business Google accounts. I’ll use the business one to sign up, which already has a bank card associated with it. Ugh, it didn’t accept the first card and got an error. I had to use a different card.

One of the things I dislike about using Google Cloud is they make everything so complex. It’s asking me to “Set Up Foundation”, which apparently is “integrated with Terraform”, whatever that is1. On the next page it gives me three options, two of which are “Coming soon”, so you have to select the middle option… Now there is a ten step process it wants me to go through to set up an organization, user groups, users, and their permissions. I don’t want to do any of this, I just want to make a web app that says “Hello world!” This sucks. I’ve decided to skip this step.

1 “Terraform is an infrastructure-as-code software tool created by HashiCorp. Users define and provide data center infrastructure using a declarative configuration language known as HashiCorp Configuration Language (HCL), or optionally JSON.” Okaaay… This is why I don’t like using Google Services.

Apparently I have 277.82 euros of free trial credits. A very strange number. I haven’t used any, to my knowledge at least. Perhaps it has converted dollars to euros? A crappy rate of exchange if they have. And apparently I have 91 days remaining of my trial. Why don’t they just state the date it ends on? 27 February apparently. I’ll add that to my calendar.

I have configured an alert if I go over 5 euros of budget a month, which I don’t intend to do… I would prefer to set a maximum spend than an alert. Let’s see if I can do that… Wow they make it complex. One option to automatically control spending is to use budget notifications to programmatically disable Cloud Billing on a project. Seriously? 😡 I’ll leave that for the moment…

Setting up the App Engine

I can’t find “App Engine” in the menu. ChatGPT says I need to explicitly enable it for my project. There is already a project set up called “My First Project” — I guess the system set that up automatically. I go to that project but “App Engine” is no where to be found. ChatGPT says I need to use search to find it. Ah, now I have a page with a big blue button that says “Create Application”. Progress! I click the button. It wants me to select a region in the world — I select europe-west. Now I need to select a service account. What is that? It only gives me one option “App Engine default service account”. My only option is to use that. It is now Creating application… apparently. It’s taking an awful long time. I haven’t even told it to print “Hello world!” yet.

It’s finished. Now it wants me to select a language — Python! — and an environment. I’ll go with “Standard”. Now I need to “Download the Cloud SDK”. I click that button and it gives me two options: “Install Google Cloud CLI” or “Contact sales”. So I’ll click the Install button… Oh crap this just takes me to another page. These buttons are just all links, they don’t actually do anything. I’m going to lunch.

Whilst at lunch it seems that Google has decided to throw me out of the account I was logged into, and use my personal account, so it’s asking me to create a Google Cloud account. If I click on the account selector top right, rather than just changing to the account I was using before it has opened yet another page, this one encouraging me to try “Vertex AI”, whatever that is. I have had to search for the page I was previously on… oh FFS if I paste the URL of the page I want to go to when I’m logged into my business account, it automatically changes account back to my personal account.

I’ve gone back to the Google Cloud Console and entered “Install the Google Cloud CLI” into the search bar. It comes up as the fourth link. I click on it, it opens a new page, logged into my personal account. I’m close to giving up with this. I have tried several things and I literally cannot view that page without it changing accounts to my personal account. Ok, let’s just follow the instructions on the page and see what happens…

Some messing around later, I have the Google Cloud CLI set up on my MacBook Pro. So I guess the first thing I should do is make sure my gcloud CLI is up to date:

gcloud components update

Deploying the Hello World app

This is my hello world app, main.py:

main.py
from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello, World!"

And the app configuration, app.yaml:

app.yaml
runtime: python39
entrypoint: python main.py

Now to deploy the app: 🥁

gcloud app deploy

Damn! It didn’t work. 😒

I had to assign roles to the service account on the IAM & Admin > IAM page:

  • Storage Admin (to manage buckets and objects during deployment)
  • Cloud Build Service Account (to allow the Cloud Build service to work properly)

I also had to ensure the staging bucket has the correct permissions:

  1. Go to Cloud Storage > Buckets in the Cloud Console.
  2. Locate the bucket [BUCKETNAME]
  3. Check the permissions for this bucket.
  4. Ensure the App Engine default service account has Storage Admin or similar permissions.

Trying to deploy again. 🥁 I must say it does take a long time. What is it doing?

Looks promising!

But the web page shows

Service unavailable

It didn’t work…

Solving the issues

Looking in the Logs Explorer in Google Cloud Console Logs Explorer, the first issue was “No module named Flask”, which is easily solved by adding a requirements.txt file. ChatGPT also recommended that I use gunicorn, so I added that too.

A Python WSGI HTTP Server is a web server designed to handle HTTP requests and serve Python web applications that follow the WSGI (Web Server Gateway Interface) standard. You are not suppose to use Flask as an entry point for production code. A WSGI HTTP Server bridges the gap between web clients (like browsers) and Python web applications or frameworks (like Flask, Django, or FastAPI).

And an update to the app.yaml:

app.yaml
runtime: python39
entrypoint: gunicorn -b :$PORT main:app

Finally!

So next what I want to do is:

  • Have simple password protection for my app, so it’s personal.
  • Use it to host my personal exercise application.
  • Have the exercise application create a CSV file which I can use to draw graphs on this website.