I'm deploying a Firebase Cloud Function using the Google-Github-Actions.
- id: onItemCreate
name: Deploy onItemCreate
uses: google-github-actions/deploy-cloud-functions@v1.0.1
with:
name: "onItemCreate"
entry_point: "onItemCreate"
runtime: ${{ env.RUNTIME }}
region: ${{ env.GCP_REGION }}
build_service_account: ${{ env.SERVICE_ACCOUNT_BUILD }}
service_account: ${{ env.SERVICE_ACCOUNT_RUN }}
event_trigger_type: "providers/cloud.firestore/eventTypes/document.create"
event_trigger_resource: "projects/my-project-id/databases/my-firestore-name/documents/items/{itemId}"
event_trigger_service_account: ${{ env.SERVICE_ACCOUNT_RUN }}
The cloud function correctly triggers whenever a document is created in /items
. But always raises the same error. Example: I create a document (id: sfgQxqkDAcGXePoKcTQB) in /items
and get the following error:
onItemCreatezd7hse2sjkl2 Error: Resource string did not match expected format: projects/my-project-id/databases/my-firestore-name/documents/items/sfgQxqkDAcGXePoKcTQB.
at splitResource (/workspace/node_modules/@google-cloud/functions-framework/build/src/middleware/background_event_to_cloud_event.js:104:19)
at backgroundEventToCloudEventMiddleware (/workspace/node_modules/@google-cloud/functions-framework/build/src/middleware/background_event_to_cloud_event.js:131:72)
at Layer.handle [as handle_request] (/workspace/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/workspace/node_modules/express/lib/router/index.js:328:13)
at /workspace/node_modules/express/lib/router/index.js:286:9
at Function.process_params (/workspace/node_modules/express/lib/router/index.js:346:12)
at next (/workspace/node_modules/express/lib/router/index.js:280:10)
at legacyPubSubEventMiddleware (/workspace/node_modules/@google-cloud/functions-framework/build/src/pubsub_middleware.js:72:5)
at Layer.handle [as handle_request] (/workspace/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/workspace/node_modules/express/lib/router/index.js:328:13)
I have no idea how to debug this because the cloud function does not even run because this error is raised before its invocation. I'm also confused because the resource does match the expected format and if it didn't, then why is the function even triggered?
Fixed it by using deploy-cloud-functions@main
and adding more configuration.
- id: onItemCreate
name: Deploy onItemCreate
uses: google-github-actions/deploy-cloud-functions@main
with:
name: "onItemCreate"
entry_point: "onItemCreate"
runtime: ${{ env.RUNTIME }}
region: ${{ env.GCP_REGION }}
build_service_account: ${{ env.SERVICE_ACCOUNT_BUILD }}
service_account: ${{ env.SERVICE_ACCOUNT_RUN }}
event_trigger_type: "google.cloud.firestore.document.v1.created"
event_trigger_resource: "projects/my-project-id/databases/my-firestore-name/documents/items/{itemId}"
event_trigger_filters: |-
database=my-firestore-name
event_trigger_service_account: ${{ env.SERVICE_ACCOUNT_RUN }}