2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

スタートガイド通りにCloud Functions for Firebaseを本番環境にデプロイできなかった

Last updated at Posted at 2022-07-10

はじめに

以下に沿って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でエンドポイントを作成したいと思います。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?