# Cloud Functions

[Cloud Function](https://cloud.google.com/functions/docs/) 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 [Spring Cloud Functions Reference Documentation](https://docs.spring.io/spring-cloud-function/docs/current/reference/html/gcp.html) for more details.

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

{% embed url="<https://www.youtube.com/watch?v=UsYRKkibLPI>" %}

## Getting Started

### Clone

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

### Build

```bash
mvn package
```

### Run Locally

```bash
mvn function:run

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

### Deploy

#### Enable API

```bash
gcloud services enable cloudfunctions.googleapis.com
```

#### Deploy

```bash
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:

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

Trigger the function with `curl`:

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

curl ${URL}
```

Alternatively, you can also use `gcloud`:

```bash
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:

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

## Learn More

* [Cloud Functions Java Runtime documentation](https://cloud.google.com/functions/docs/concepts/java-runtime)
* [Framework support](https://cloud.google.com/functions/docs/concepts/java-frameworks) for [Spring Cloud Functions](https://cloud.spring.io/spring-cloud-static/spring-cloud-function/3.0.7.RELEASE/reference/html/gcp.html), [Micronaut](https://micronaut-projects.github.io/micronaut-gcp/2.0.x/guide/#cloudFunction), [Quarkus](https://quarkus.io/guides/gcp-functions)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://spring-gcp.saturnism.me/getting-started/helloworld/cloud-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
