Spring Boot on GCP
  • Introduction
  • Getting Started
    • Google Cloud Platform
    • Cloud Shell
    • gcloud CLI
    • Hello World!
      • Cloud Shell
      • App Engine
      • Cloud Run
      • Kubernetes Engine
      • Compute Engine
      • Cloud Functions
  • Application Development
    • Development Tools
    • Spring Cloud GCP
    • Cloud Services
      • Databases
        • Cloud SQL
        • Cloud Spanner
        • Cloud Firestore
          • Datastore Mode
          • Native Mode
      • Messaging
        • Cloud Pub/Sub
        • Kafka
      • Secret Management
      • Storage
      • Cache
        • Memorystore Redis
        • Memorystore Memcached (beta)
      • Other Services
    • Observability
      • Trace
      • Logging
      • Metrics
      • Profiling
      • Debugging
    • DevOps
      • Artifact Repository
  • Deployment
    • Runtime Environments
    • Container
      • Container Image
      • Secure Container Image
      • Container Awareness
      • Vulnerability Scanning
      • Attestation
    • Kubernetes
      • Kubernetes Cluster
      • Deployment
      • Resources
      • Service
      • Health Checks
      • Load Balancing
        • External Load Balancing
        • Internal Load Balancing
      • Scheduling
      • Workload Identity
      • Binary Authorization
    • Istio
      • Getting Started
      • Sidecar Proxy
  • Additional Resources
    • Code Labs
    • Presentations / Videos
    • Cheat Sheets
Powered by GitBook
On this page
  • Getting Started
  • Clone
  • Build
  • Run Locally
  • Deploy
  • Connect
  • Additional Configurations
  • Learn More

Was this helpful?

  1. Getting Started
  2. Hello World!

Cloud Functions

Deploy a simple HTTP function.

PreviousCompute EngineNextDevelopment Tools

Last updated 4 years ago

Was this helpful?

is a scalable, pay as you go, Functions-as-a-Service (FaaS).

Spring Cloud Functions has pre-GA support for Cloud Functions for Java 11. See for more details.

This guide currently uses a non-Spring example for Cloud Functions.

Getting Started

Clone

cd $HOME
git clone https://github.com/GoogleCloudPlatform/java-docs-samples
cd java-docs-samples/functions/helloworld/helloworld

Build

mvn package

Run Locally

mvn function:run

# In a different tab, trigger the function:
curl localhost:8080

Deploy

Enable API

gcloud services enable cloudfunctions.googleapis.com

Deploy

gcloud functions deploy helloworld --trigger-http \
  --runtime=java11 \
  --entry-point=functions.HelloWorld \
  --allow-unauthenticated

Connect

Once a HTTP function is deployed, you can connect to it using curl. You can also find the URL:

gcloud functions describe helloworld --format='value(httpsTrigger.url)'

Trigger the function with curl:

URL=$(gcloud functions describe helloworld --format='value(httpsTrigger.url)')

curl ${URL}

Alternatively, you can also use gcloud:

gcloud functions call helloworld

Additional Configurations

By default, Cloud Functions will deploy to the smallest 256MB instance. You can specify a larger instance and configure environment variables with the gcloud CLI:

gcloud functions deploy helloworld --trigger-http \
  --runtime=java11 \
  --memory=512M
  --entry-point=functions.HelloWorld \
  --allow-unauthenticated

Learn More

for , ,

Cloud Functions Java Runtime documentation
Framework support
Spring Cloud Functions
Micronaut
Quarkus
Cloud Function
Spring Cloud Functions Reference Documentation