LoginSignup
0
0

CloudFunctionのonCallでRegionを指定する

Posted at

はじめに

Cloud FunctionsをそのままFirebase CLIからデプロイすると、デフォルトのリージョンus-central1に設定されてしまいます。
スクリーンショット 2024-03-08 7.10.09.png

また、デプロイしてしまうとリージョンが変更できないので、デプロイする前に設定しなければなりません。

書き方

Cloud Functionsの第2世代が公開されてますが、第1世代と第2世代では設定方法が変更されています。
以下、typescriptで作成しています。

第1世代

import * as functions from 'firebase-functions'

export const testFunction = functions 
  .region('asia-northeast1')  
  .https  
  .onCall((req) => {
    // onCallの処理
  })

第2世代

import * as functions from 'firebase-functions/v2'

export const testfunction = functions
  .https
  .onCall({region: 'asia-northeast1'}() => {
    // onCallの処理
  })
  • 関数名が第2世代では大文字が使えず、小文字だけになった。
  • リージョンを指定する場所
    が変更されています。(これはonRequestも同様です)

結果

スクリーンショット 2024-03-08 7.08.15.png

公式ドキュメントにも設定方法が載っています。

参考
https://zenn.dev/nananaoto/articles/3efc945c845910

0
0
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
0
0