1. Deploy Functions
gcloud functions deploy .
2. Cloud Functionsでentrypointを指定する
script_cloud_functions.py
def function_name():
print("hello world")
--set-build-env-vars GOOGLE_FUNCTION_SOURCE=script_cloud_functions.py
-
--entry-point=function_name
(GOOGLE_FUNCTION_TARGET
これでもOKなはず)
gcloud functions deploy test-function \
--gen2 \
--runtime python312 \
--set-secrets SLACK_WEBHOOK_URL=slack-webhook-url-dev:latest \
--set-build-env-vars GOOGLE_FUNCTION_SOURCE=script_cloud_functions.py \
--project $PROJECT \
--region $REGION \
--service-account test-function@${PROJECT}.iam.gserviceaccount.com \
--source . \
--entry-point=function_name \
--allow-unauthenticated \
--trigger-http
Cloud Run and Cloud Functions environment variables
3. invoke cloud function
gcloud functions call $FUNCTION_NAME \
--gen2 \
--project $PROJECT \
--region $REGION \
--data "{\"specversion\": \"1.0\",\"source\": \"//cloudaudit.googleapis.com/projects/test-project/logs/data_access\",\"type\": \"google.cloud.audit.log.v1.written\", \"id\": \"projects/test-project/logs/cloudaudit.googleapis.com%2Fdata_access1234567123456789\", \"data\": {\"protoPayload\": {\"resourceName\": \"projects/_/buckets/sample-bucket/objects/filename.png\"}}}"