- Google Cloud Console account
- Cloud SQL instance
- 2nd-gen Cloud Function
- Cloud Run API enabled
- Cloud SQL Admin API enabled
- Google Cloud IAM privileges & roles
- Google Cloud Service Accounts
- Google Cloud Run
- Google Cloud Secrets
- Prisma
- Node 16
- nvm use 16 - Switch to Node 16 (nvm install 16.5.1 if not installed)
- npm install - Install all node_modules for the GCF
- **DATABASE_URL=mysql://<user>:<pass>@localhost/<database> npx prisma migrate dev --name init - Run migrations to create tables inside the database.
- DATABASE_URL=mysql://<user>:<pass>@localhost/<database> npx @google-cloud/functions-framework --target=run - Serve the example GCF locally
- http://localhost:8080/ - Visit the locally served GCF
After cloning this repository, you can upload a zip of the example GCF directory directly to a created Cloud Function. Alternatively, you can manually create & copy GCF files and their contents into your created Cloud Function.
The url property for the datasource object is typically set to env("DATABASE_URL"). This requires your Cloud Function to have access to a stored secret named DATABASE_URL. This variable is formatted as such for MySQL: mysql://<user>:<pass>@localhost/<database>