Go 1.11 はサポートが終了しており、2026 年 1 月 31 日に
非推奨になります。非推奨になると、過去に組織のポリシーを使用して以前のランタイムのデプロイを再度有効にしていた場合でも、Go 1.11 アプリケーションをデプロイできなくなります。既存の Go 1.11 アプリケーションは、
非推奨日以降も引き続き実行され、トラフィックを受信します。
サポートされている最新バージョンの Go に移行することをおすすめします。
Cloud Storage の使用
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Go 1.11 アプリで実行時にファイルを読み書きする必要がある場合や、ムービー、画像などの静的コンテンツを提供する必要がある場合は、Cloud Storage バケットの使用をおすすめします。
アプリを作成すると、App Engine がデフォルトのバケットを作成します。このバケットでは、ストレージの最初の 5 GB が無料で提供され、Cloud Storage I/O オペレーションの無料の割り当ても用意されています。別の Cloud Storage バケットを作成することもできますが、無料の 5 GB ストレージが用意されているのは、デフォルトのバケットのみです。
App Engine での Cloud Storage の使用
App Engine アプリから Cloud Storage バケットを使用するには:
App Engine プロジェクトで既存のバケットの名前を確認します。Cloud Storage との間でデータをアップロードまたはダウンロードするときに、この名前を指定します。
Cloud Storage バケットの名前をアプリにハード コーディングするのではなく、アプリの環境変数に保存することをおすすめします。
go get cloud.google.com/go/storage
コマンドを使用することによって、アプリで Cloud Storage を依存関係として宣言します。または、アプリの go.mod
ファイルで依存関係を宣言することもできます。詳しくは、依存関係を指定する方法をご覧ください。
Google Cloud クライアント ライブラリを使用して、バケットとの間でデータをアップロードまたはダウンロードします。
静的コンテンツの提供については、静的ファイルの保存と提供をご覧ください。
デフォルト バケットの使用
アプリを作成すると、App Engine により、最初の 5 GB のストレージを無料で提供するデフォルトのバケットが作成されます。また、デフォルトのバケットには、Cloud Storage I/O オペレーション用の無料の割り当ても含まれています。詳しくは、料金、割り当て、上限をご覧ください。ストレージが 5 GB の上限を超えると課金が開始します。
デフォルト バケットの名前は、次の形式で指定されます。
project-id.appspot.com
App Engine は、アプリの新しいバージョンをデプロイする際に、一時ストレージに使用するバケットも作成します。staging.project-id.appspot.com
という名前のこのバケットは、App Engine でのみ使用できます。アプリはこのバケットとはやり取りできません。
バケットとオブジェクトの権限の設定
アプリに関連付けるサービス アカウントには、プロジェクトでバケットとの間で読み取りと書き込みをするための権限が必要です。必要な権限については、Cloud Storage に適用される IAM のロールをご覧ください。
多くの場合、アプリに関連付けるサービス アカウントは、デフォルトの App Engine サービス アカウントです。
組織のポリシー構成によっては、デフォルトのサービス アカウントにプロジェクトの編集者のロールが自動的に付与される場合があります。iam.automaticIamGrantsForDefaultServiceAccounts
組織ポリシー制約を適用して、自動的なロール付与を無効にすることを強くおすすめします。2024 年 5 月 3 日以降に組織を作成した場合、この制約はデフォルトで適用されます。
自動ロール付与を無効にする場合、デフォルトのサービス アカウントに付与するロールを決定し、これらのロールを付与する必要があります。
デフォルトのサービス アカウントにすでに編集者ロールが設定されている場合は、編集者ロールを権限の低いロールに置き換えることをおすすめします。サービス アカウントのロールを安全に変更するには、Policy Simulator を使用して変更の影響を確認してから、適切なロールを付与または取り消す操作を行います。
他のユーザー、アプリ、プロジェクトがバケットとその内容にアクセスできるようにするには、バケットの権限の設定とオブジェクトの権限の設定をご覧ください。
ローカル開発用サーバーでの Cloud Storage の使用
App Engine のローカル開発用サーバーは、Cloud Storage をエミュレートしないため、インターネットを介して、すべての Cloud Storage リクエストを実際の Cloud Storage バケットに送信する必要があります。
料金、割り当て、制限
Cloud Storage への Cloud Storage クライアント ライブラリの呼び出しに関連する帯域幅課金はありません。ただし、オペレーション料金は適用されます。また、ライブラリは URL 取得サービスを使用して Cloud Storage とやり取りするため、呼び出しは URL の取得割り当てに対してカウントされます。
なお、Cloud Storage は従量課金サービスであり、Cloud Storage の価格表に従って課金されることに注意してください。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-09-04 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-04 UTC。"],[[["\u003cp\u003eApp Engine recommends using a Cloud Storage bucket for reading, writing, and serving files during runtime in Go 1.11 apps.\u003c/p\u003e\n"],["\u003cp\u003eWhen you create an app, App Engine provides a default bucket with the first 5GB of storage and a free quota for Cloud Storage I/O operations.\u003c/p\u003e\n"],["\u003cp\u003eTo interact with Cloud Storage from your app, you should specify bucket names using environment variables and declare Cloud Storage as a dependency using the \u003ccode\u003ego get\u003c/code\u003e command.\u003c/p\u003e\n"],["\u003cp\u003eApp Engine automatically creates a temporary staging bucket for deploying new versions, but it's not accessible to apps.\u003c/p\u003e\n"],["\u003cp\u003eThe service account linked to your app needs the appropriate permissions to interact with buckets, and you should consider replacing the Editor role with more restrictive roles for enhanced security.\u003c/p\u003e\n"]]],[],null,["# Using Cloud Storage\n\nIf your Go 1.11 app needs to read and write files during runtime,\nor serve files such as movies, images or other static content, we recommend you\nuse a [Cloud Storage](/storage/docs) bucket.\n\nApp Engine creates a [default bucket](#default_bucket) when you create\nan app. This bucket provides the first 5GB of storage for free and includes a\nfree quota for Cloud Storage I/O operations. You can\n[create other Cloud Storage buckets](/storage/docs/creating-buckets),\nbut only the default bucket includes the first 5GB of storage for free.\n\nUsing Cloud Storage with App Engine\n-----------------------------------\n\nTo use a Cloud Storage bucket from an App Engine app:\n\n1. [View the names of the existing buckets](/storage/docs/listing-buckets)\n in your App Engine project. You'll specify these names when you\n upload or download data from Cloud Storage.\n\n We recommend that you store the names of your Cloud Storage buckets\n in your app's [environment variables](/appengine/docs/standard/reference/app-yaml#environment_variables)\n instead of hard coding them into your app.\n2. In your app, declare Cloud Storage as a dependency\n\n by using the `go get cloud.google.com/go/storage` command. Alternatively,\n you can declare dependencies in your app's `go.mod` file. Learn more\n [about specifying dependencies](/appengine/docs/legacy/standard/go111/specifying-dependencies).\n\n \u003cbr /\u003e\n\n3.\n Use the Google Cloud Client Library to\n [upload](/storage/docs/uploading-objects)\n or [download](/storage/docs/downloading-objects)\n data from your buckets.\n\n\n For information about serving static content, see [Storing and Serving\n Static Files](/appengine/docs/legacy/standard/go111/serving-static-files).\n\n### Using the default bucket\n\nWhen you create an app, App Engine creates a default bucket that\nprovides the first 5GB of storage for free. The default bucket also includes\na free quota for Cloud Storage I/O operations. See\n[Pricing, quotas, and limits](#pricing_quotas_and_limits) for details. You will\nbe charged for storage over the 5GB limit.\n\nThe name of the default bucket is in the following format: \n\n```\nproject-id.appspot.com\n```\n\n\u003cbr /\u003e\n\nApp Engine also creates a bucket that it uses for temporary\nstorage when it deploys new versions of your app. This bucket, named\n`staging.`\u003cvar translate=\"no\"\u003eproject-id\u003c/var\u003e`.appspot.com`, is for use by\nApp Engine only. Apps can't interact with this bucket.\n\n### Setting bucket and object permissions\n\nThe service account that's associated with your app needs permissions to read\nand write to buckets in your project. To learn which permissions are required,\nsee [IAM roles for\nCloud Storage](/storage/docs/access-control/iam-roles).\n\nTypically, the\nservice account that's associated with your app is the [default\nApp Engine service\naccount](/appengine/docs/legacy/standard/go111/service-account).\n\n\nDepending on your organization policy configuration, the default service account might\nautomatically be granted the [Editor role](/iam/docs/roles-overview#basic) on your\nproject. We strongly recommend that you disable the automatic role grant by [enforcing the `iam.automaticIamGrantsForDefaultServiceAccounts` organization policy\nconstraint](/resource-manager/docs/organization-policy/restricting-service-accounts#disable_service_account_default_grants). If you created your organization after May 3, 2024, this\nconstraint is enforced by default.\n\n\nIf you disable the automatic role grant, you must decide which roles to grant to the default\nservice accounts, and then [grant these\nroles](/iam/docs/granting-changing-revoking-access) yourself.\n\n\nIf the default service account already has the Editor role, we recommend that you replace the\nEditor role with less permissive roles.To safely modify the service account's roles, use [Policy Simulator](/policy-intelligence/docs/simulate-iam-policies) to see the impact of\nthe change, and then [grant and revoke the\nappropriate roles](/iam/docs/granting-changing-revoking-access).\n\n\u003cbr /\u003e\n\nFor information about allowing other users, apps, or projects to access a bucket\nand its contents, see\n[Setting bucket permissions](/storage/docs/cloud-console#_bucketpermission)\nand\n[Setting object permissions](/storage/docs/cloud-console#_permissions).\n\nUsing Cloud Storage with the local development server\n-----------------------------------------------------\n\nThe App Engine local development server doesn't emulate Cloud Storage,\nso all Cloud Storage requests must be sent over the Internet to an\nactual Cloud Storage bucket.\n\nPricing, quotas, and limits\n---------------------------\n\nThere are no bandwidth charges associated with Cloud Storage client library\ncalls to Cloud Storage. However, there are\n[operations charges](/storage/pricing#operations-pricing).\nIn addition, the calls count against your\n[URL fetch quota](/appengine/docs/quotas#UrlFetch)\nas the library uses the URL Fetch service to interact with Cloud Storage.\n\nNotice that Cloud Storage is a pay-to-use service;\nyou will be charged according to the Cloud Storage\n[price sheet](/storage/pricing)."]]