Cloud Functions(第 1 世代)を Cloud Storage バケットへのファイルアップロードをトリガーとして Python 3.9 でデプロイしたいと考えています。正しいコマンドはどれですか?
- A. gcloud run deploy my-function --trigger-bucket=my-bucket --runtime=python39
- B. gcloud functions deploy my-function --runtime=python39 --trigger-event=google.storage.object.finalize --trigger-resource=my-bucket --entry-point=process_file
- C. gcloud functions create my-function --runtime=python39 --trigger-bucket=my-bucket
- D. gcloud functions deploy my-function --runtime=python39 --trigger-bucket=my-bucket --entry-point=process_file
解答と解説を見る
正解: B
Cloud Functions でストレージトリガーを設定するには、--trigger-event と --trigger-resource を組み合わせます。google.storage.object.finalize はオブジェクトのアップロード(作成・上書き)をトリガーするイベントです。--trigger-bucket は第 1 世代で使用できる省略記法ですが、より明示的な --trigger-event + --trigger-resource が確実です。選択肢D の --trigger-bucket 構文自体は動作しますが、--entry-point との組み合わせが現行の正式な形式ではありません。選択肢C は deploy ではなく create と誤っています(正しくは deploy)。選択肢A は Cloud Run のコマンドで、Cloud Functions には使えません。