Skip to main content
GitHub Repository

You can find the project source code on GitHub.

Prerequisites#

  1. Create a Google Cloud Project.
  2. Enable billing for your project.
  3. Enable the Cloud Run, Cloud Build, Artifact Registry, and Cloud Logging APIs.

Database Setup#

Create a Redis database using Upstash Console or Upstash CLI. Copy UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN for the next steps.

Counter Function Setup & Deploy#

Google Cloud Functions is now part of Cloud Run, as Cloud Run functions. You create and deploy functions from the Cloud Run console.

  1. Go to Cloud Run in Google Cloud Console.
  2. Click Write a function.
  3. Enter a service name, pick a region, and select a recent Node.js runtime.
Create a Google Cloud Run function
  1. Under Authentication, select Allow public access.
  2. Expand the Containers, Volumes, Networking, Security section. In the Variables & Secrets tab, add the UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN environment variables with the values from your database.
Redis environment variables in Google Cloud Run
  1. Click Create. The console creates the service and opens the inline source editor.
  2. Set Function entry point to counter.
Set the Google Cloud Run function entry point
Warning

The entry point must match the name you register with functions.http('counter', ...) below. If it stays at the default helloHttp, the container starts no server and the deploy fails with a “failed to start and listen on PORT 8080” error.

  1. Update index.js
index.js
  1. Update package.json to include @upstash/redis.
package.json
  1. Click Save and redeploy.
  2. Visit the URL shown at the top of the service page.