LoginSignup
2
1

More than 1 year has passed since last update.

[Cloudfunctions] Your proposed upload is larger than the maximum object size specified in your Policy Document.

Posted at

エラー

CloudFunctionsのデプロイでコケる。

$ gcloud functions deploy test_func \
    --trigger-http \
    --allow-unauthenticated \
    --region=asia-northeast1 \
    --runtime=python39
ERROR: (gcloud.functions.deploy) Failed to upload the function source code to signed url: https://storage.googleapis.com/gcf-upload-asia-northeast1-xxxx.zip?GoogleAccessId=service-xxxx@xxxxx.iam.gserviceaccount.com&Expires=xxxxx&Si.
Status: [400:b"<?xml version='1.0' encoding='UTF-8'?><Error><Code>EntityTooLarge</Code>
<Message>Your proposed upload is larger than the maximum object size specified in your Policy Document.</Message><Details>Content-length exceeds upper bound on range</Details></Error>"]

原因

アップロードするファイルサイズが大きすぎるらしい。
下記画像が、CloudFunctionsのデプロイ最大サイズ。

Your proposed upload is larger than the maximum object size specified in your Policy Document.

Googleの公式ドキュメントに書いてありました。
スクリーンショット 2021-12-06 17.24.06.png

解決策

.gcloudignoreにデプロイに不要なファイル・ディレクトリを追記する。
これによって、デプロイ時のアップロードサイズを減らせる。

1. サイズの大きなファイル・ディレクトリを特定

隠しファイルも見たいので、-aオプションつけてます。

$ tree --du -h -a --sort=size
.
├── [ 92M]  venv

...

├── [109M]  bin
├── [ 144]  .env
├── [2.8K]  __pycache__
├── [8.0K]  crawler
├── [ 744]  model
│   ├── [ 113]  item.py
│   └── [ 503]  __pycache__
│       └── [ 407]  item.cpython-39.pyc
├── [  67]  .gcloudignore
└── [  22]  .gitignore

  14K used in 6 directories, 9 files

 7.1K used in 5 directories, 5 files

2. デプロイに必要の無いファイル・ディレクトリを.gcloudignoreに追加

.gcloudignore
.DS_Store
.git
.gitignore
README.md
__pycache__/
venv

3. 再度デプロイ

無事、デプロイが通りました。

$ gcloud functions deploy test_func \
    --trigger-http \
    --allow-unauthenticated \
    --region=asia-northeast1 \
    --runtime=python39
Deploying function (may take a while - up to 2 minutes)...⠛
For Cloud Build Logs, visit: https://console.cloud.google.com/cloud-build/builds;region=asia-northeast1/xxxx
Deploying function (may take a while - up to 2 minutes)...done.
availableMemoryMb: 256
buildId: xxxx
buildName: projects/xxxx
entryPoint: test_func
httpsTrigger:
  securityLevel: SECURE_OPTIONAL
  url: https://asia-northeast1-xxxx
ingressSettings: ALLOW_ALL
labels:
  deployment-tool: cli-gcloud
name: projects/temille-dev/locations/asia-northeast1/functions/test_func
runtime: python39
serviceAccountEmail: xxxx@appspot.gserviceaccount.com
sourceUploadUrl: https://storage.googleapis.com/gcf-upload-asia-northeast1xxxx.zip
status: ACTIVE
timeout: 60s
updateTime: '2021-12-06T09:02:57.043Z'
versionId: '12'
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