cloud-run-sql-task-api

Cloud Run + Cloud SQL Task API

This project demonstrates how to build and deploy a containerized API using Google Cloud.

The API allows users to add and retrieve tasks stored in a PostgreSQL database hosted in Cloud SQL.

Architecture:

User → Cloud Run API → Cloud SQL (PostgreSQL)

Tech Stack

  • Python
  • Flask
  • Docker
  • Google Cloud Run
  • Google Cloud SQL (PostgreSQL)
  • PostgreSQL
  • Gunicorn

API Endpoints

POST /task

Add a new task.

Example request:

{ "task": "Study Cloud Run" }

GET /tasks

Retrieve all tasks stored in the database.

Example response:

[ [1, "Study Cloud Run"] ]

Deployment Steps

  1. Build Docker image
  2. Push to Google Container Registry
  3. Deploy to Cloud Run
  4. Connect to Cloud SQL
  5. Test using curl

Example test commands:

curl -X POST https://YOUR_URL/task \ -H "Content-Type: application/json" \ -d '{"task":"Study Cloud Run"}'

curl https://YOUR_URL/tasks

Learning Outcomes

  • Deploy containerized applications
  • Connect Cloud Run with Cloud SQL
  • Handle PostgreSQL permissions
  • Debug cloud deployment issues
  • Build production-style cloud APIs

Future Improvements

  • VPC private networking
  • Secret Manager integration
  • CI/CD pipeline with GitHub Actions
  • Terraform infrastructure automation

Built With

Share this project:

Updates