This is an example of GCP function using Typescript and Yarn.
- Download Google Cloud SDK
- Initialize gcloud config ($ gcloud init)
- Log in to gcloud account ($ gcloud auth login)
At the first time running the project run the command:
$ yarnThen you can build and start the local dev:
$ yarn gcp:build
$ yarn gcp:devOnce the project is running check out http://localhost:8081.
Deploy the GCP function (cd examples/with-gcp)
$ gcloud functions deploy gcp-function \
--entry-point=handler \
--runtime nodejs20 \
--trigger-http \
--allow-unauthenticated \
--project [PROJECT ID]access the URL (example): https://us-central1-zinc-style-449212-s0.cloudfunctions.net/gcp-function
If authentication is required (--no-allow-unauthenticated), execute this line:
$ curl -H "Authorization: Bearer $(gcloud auth print-identity-token)" \
[FUNCTION URL]more info: https://cloud.google.com/functions/docs/securing/authenticating
To invoke the GCP function directly, execute this line:
$ gcloud functions call [FUNCTION NAME]more info: https://cloud.google.com/functions/docs/running/direct