Intro To Google Cloud

Intro To Google Cloud

Reading time1 min
#Cloud#Google#Python#GCP#Firestore#AppEngine

How to Build Your First Application on Google Cloud Platform: Step-by-Step for Engineers


Cloud infrastructure underpins nearly every modern software deployment. Among major providers, Google Cloud Platform (GCP) offers competitive managed compute and storage, well-documented APIs, and tight integration with Google’s data products. If you want to ship production-grade applications without wrestling VMs or manually scaling clusters, start with GCP’s serverless toolchain.

This walkthrough produces a functioning web application using:

  • App Engine (Standard Environment) for hands-off deployment and auto-scaling.
  • Cloud Firestore (Native mode) for low-latency, NoSQL storage.

This isn’t toy code: with minor tweaks, the application can fit real business needs.


1. Environment Setup

Account & Project

  • Register at https://console.cloud.google.com (new accounts receive $300/90d credits—enough for extensive prototyping).
  • Create a new GCP project:
    • Click top-left project menu → “New Project”.
    • Name it, e.g., my-first-cloud-solution.
    • Select billing; project resources and quotas are isolated per project.

Keeping each solution in a separate project avoids cross-contamination of quotas and IAM policies.


Permissions

Ensure your user account is assigned at least the Project Editor role. For deployment, App Engine and Firestore APIs require explicit enablement.


2. Local Development Prerequisites

  • macOS, Linux, or Windows (WSL2 recommended if Windows).
  • Python 3.10+ (python3 --version).
  • Cloud SDK (gcloud CLI).
    • After install, run gcloud init and select your new project.

Flask and the Firestore Python client will be managed through pip.

Remember: mismatched Python package versions are a common source of runtime errors during local testing vs. cloud deployment.


requirements.txt:

Flask==2.0.3
google-cloud-firestore==2.8.0

3. Prototype the Application

Target behavior: collect user-submitted names in a simple HTTP POST form, store entries in Firestore, and display all submissions.

Directory structure:

my-first-cloud-solution/
├── app.yaml
├── main.py
└── requirements.txt

main.py

from flask import Flask, request, render_template_string
from google.cloud import firestore

app = Flask(__name__)
db = firestore.Client()

FORM_HTML = """
<!doctype html>
<title>GCP Guestbook</title>
<h1>Sign the Guestbook</h1>
<form method=post>
  Name: <input type=text name=name>
  <input type=submit value=Submit>
</form>
<ul>
{% for entry in entries %}
  <li>{{ entry }}</li>
{% endfor %}
</ul>
"""

@app.route("/", methods=["GET", "POST"])
def guestbook():
    if request.method == "POST":
        name = request.form.get("name")
        if name:
            db.collection("guestbook").add({"name": name})
    entries = [doc.to_dict().get("name")
               for doc in db.collection("guestbook").stream()]
    return render_template_string(FORM_HTML, entries=entries)

if __name__ == "__main__":
    app.run(host="127.0.0.1", port=8080, debug=True)

app.yaml

runtime: python310

handlers:
- url: /.*
  script: auto

4. Cloud Service Activation

Activate APIs before deploying.

  • In console, navigate: APIs & Services → Library.
    • Enable App Engine Admin API.
    • Enable Cloud Firestore API.

Create Firestore database:

  • Left menu: Firestore Database → Create database → Native mode.
    • Pick region; note that region cannot be changed later.
    • Ignore multi-region unless explicit compliance needs.

Default App Engine service account is granted broad permissions, but in prod, tighten IAM boundaries.


5. First Deployment

From project directory:

gcloud config set project my-first-cloud-solution
gcloud app deploy app.yaml --quiet
  • Deploy may prompt for region selection (e.g., us-central).
  • First deployment takes several minutes (provisioning service).

Common deploy error:
google.api_core.exceptions.PermissionDenied: 403 The caller does not have permission
— usually caused by missing API enablement or insufficient IAM permissions.

Open application:

gcloud app browse

6. Application Verification

On success, hitting the browser URL produces a live guestbook. Submissions update in real time as Firestore syncs almost instantly.

Questions to ask at this stage:

  • Did you see errors like Could not automatically determine credentials?
    Ensure your environment is authenticated: gcloud auth application-default login.

  • Is the form accepting duplicate names?
    Implement Firestore security rules or de-duplication logic if necessary.


7. Expanding Practicality (Notes from the Field)

  • Authentication: To prevent spam or abuse, integrate Firebase Auth. This is non-trivial—expect to modify both Flask and Firestore access patterns.
  • Static asset serving: For large files or images, offload to Cloud Storage (with signed URLs).
  • Monitoring: Use Cloud Monitoring (ex-Stackdriver) for latency metrics, error rates, and custom logging. print() in code is insufficient for observability at scale.
  • Local Testing: Sometimes, google-cloud-firestore fails locally due to missing emulators or credentials. The emulator can be run with:
    gcloud beta emulators firestore start
    
    Then point the application via export FIRESTORE_EMULATOR_HOST=localhost:8080.

Gotcha

App Engine Standard restricts network and local file access—files written to disk in /tmp/ only. For workloads needing custom binaries or OS-level tweaks, use App Engine Flex or GKE instead, but expect higher costs and more configuration.


Table: GCP Service Quick Reference

ServicePurposeKey Limits/Notes
App Engine StdServerless HostingLimited CPU/Memory, sandboxed FS
Firestore (N)NoSQL DB1MB document size, regional lock
Cloud SDKCLI/AdminVersioned; frequent breaking API

Non-Obvious: Deployment Rollbacks

Every deploy triggers a new version. The GCP Console “Versions” tab allows instant rollbacks — useful if a new push breaks your app, but beware: data model rollback is manual.


Launching cloud-native solutions on GCP begins with small, repeatable steps. The above example employs minimal infrastructure, leverages robust managed services, and is productionizable with reasonable effort.

Explore the official tutorials for deeper, service-specific examples. Real learning accelerates once you integrate with CI/CD, secrets management, and production IAM policies.


If you encounter problems such as credential mismatches, API quota errors, or unhandled 500s in the logs—don’t ignore them. Each surfaced error is an opportunity to refine both code and deployment workflows.

For further questions—custom architecture, CI integration, or deep dives into GCP IAM nuances—open a discussion or submit a pull request with your scenario.