はじめに
以下に沿ってCloud Functions for Firebaseをデプロイしようとしたが、いくつかエラーにひっかかったので、エラー内容と解決策を提示しておきます
1. プランが対応していない
エラー
Error: Your project hogehoge must be on the Blaze (pay-as-you-go) plan to complete this command. Required API cloudbuild.googleapis.com can't be enabled until the upgrade is complete. To upgrade, visit the following URL:
https://console.firebase.google.com/project/hogehoge/usage/details
解決策
表示されたURLへアクセスして、Blazeプランへ変更します。
プランに関しては、以下をご参考ください。
2. Artifact Registry APIが有効ではない
エラー
https://cloudfunctions.googleapis.com/v1/projects/hogehoge/locations/us-central1/functions/helloWorld {"error":{"code":403,"message":"Cloud Functions uses Artifact Registry to store function docker images. Artifact Registry API is not enabled in your project. To enable the API, visit https://console.developers.google.com/apis/api/artifactregistry.googleapis.com/overview?project=hogehoge or use the gcloud command 'gcloud services enable artifactregistry.googleapis.com' then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.","status":"PERMISSION_DENIED"}}
解決策
Cloud Functions uses Artifact Registry to store function docker images. Artifact Registry API is not enabled in your project.
とあるように、Artifact Registry APIを有効にする必要があります。提示されたURLをもとにArtifact Registry APIの管理画面に遷移して、有効にします。今回の場合は以下が提示されたURLにあたります↓
https://console.cloud.google.com/artifacts/docker/hogehoge/us-central1/gcf-artifacts
Artifact Registry APIに関しては以下のURLをご参考ください
3. 権限がない
エラー
ブラウザでリクエストを飛ばすと
Error: Forbidden
Your client does not have permission to get URL /api from this server.
解決策
デフォルト設定では、起動元の認証が必要な場合があります。未認証の呼び出しを許可するために以下の手順で設定を行います。
終わりに
Cloud Functionsのエラー文は、次どうする、がとても分かり易かったです。
この観点は、アプリ開発者として参考にしていきます。
また、今までFirebase Hostingしか自分ではやってこなかったので、また一つできることが増えてよかったです。個人の開発だったとしても、Cloud Functions for Firebaseは簡単にデプロイできるので、試しやすいなと思いました。
次回は、Node.jsでエンドポイントを作成したいと思います。