This tutorial shows you how to write an HTTP Cloud Run function that submits a query to BigQuery.
Prepare the application
Clone the sample application repository to your local machine:
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
Alternatively, download the sample as a zip file and extract it.
Change to the directory that contains the sample code:
cd nodejs-docs-samples/functions/v2/helloBigQuery
Take a look at the sample code. The sample submits a query for words that occur at least 400 times in the specified dataset, and returns the result.
Deploy the function
To deploy the function with an HTTP trigger:
Run the following command in the directory that contains the sample code:
gcloud run deploy FUNCTION \ --source . \ --function FUNCTION_ENTRYPOINT \ --base-image BASE_IMAGE \ --region REGION \ --allow-unauthenticated
Replace:
FUNCTION with the name of the function you are deploying, for example
my-bigquery-function
. You can omit this parameter entirely, but you will be prompted for the name if you omit it.FUNCTION_ENTRYPOINT with the entry point to your function in your source code. This is the code Cloud Run executes when your function runs. The value of this flag must be a function name or fully-qualified class name that exists in your source code. The entry point you must specify for the sample function is
helloBigQuery
.BASE_IMAGE with the base image environment for your function, for example,
nodejs22
. For details about base images and the packages included in each image, see Runtimes base images.REGION with the Google Cloud region where you want to deploy your function. For example,
europe-west1
.
Optional:
- If you are creating a public HTTP function, for example a webhook,
specify the
--allow-unauthenticated
flag. This flag assigns the Cloud Run IAM Invoker role to the special identifierallUser
. You can use IAM to edit this setting later after you create the service.
Test the function
When the function finishes deploying, copy the
uri
property.Visit this URI in your browser.
You should see a list of the words that match the query criteria, and how many times each word appears in the target dataset.