If your Go 1.11 app needs to read and write files during runtime, or serve files such as movies, images or other static content, we recommend you use a Cloud Storage bucket.
App Engine creates a default bucket when you create an app. This bucket provides the first 5GB of storage for free and includes a free quota for Cloud Storage I/O operations. You can create other Cloud Storage buckets, but only the default bucket includes the first 5GB of storage for free.
Using Cloud Storage with App Engine
To use a Cloud Storage bucket from an App Engine app:
View the names of the existing buckets in your App Engine project. You'll specify these names when you upload or download data from Cloud Storage.
We recommend that you store the names of your Cloud Storage buckets in your app's environment variables instead of hard coding them into your app.
In your app, declare Cloud Storage as a dependency by using the
go get cloud.google.com/go/storage
command. Alternatively, you can declare dependencies in your app'sgo.mod
file. Learn more about specifying dependencies.Use the Google Cloud Client Library to upload or download data from your buckets.
For information about serving static content, see Storing and Serving Static Files.
Using the default bucket
When you create an app, App Engine creates a default bucket that provides the first 5GB of storage for free. The default bucket also includes a free quota for Cloud Storage I/O operations. See Pricing, quotas, and limits for details. You will be charged for storage over the 5GB limit.
The name of the default bucket is in the following format:
project-id.appspot.com
App Engine also creates a bucket that it uses for temporary
storage when it deploys new versions of your app. This bucket, named
staging.project-id.appspot.com
, is for use by
App Engine only. Apps can't interact with this bucket.
Setting bucket and object permissions
The service account that's associated with your app needs permissions to read and write to buckets in your project. To learn which permissions are required, see IAM roles for Cloud Storage.
Typically, the service account that's associated with your app is the default App Engine service account.
Depending on your organization policy configuration, the default service account might
automatically be granted the Editor role on your
project. We strongly recommend that you disable the automatic role grant by
enforcing the iam.automaticIamGrantsForDefaultServiceAccounts
organization policy
constraint. If you created your organization after May 3, 2024, this
constraint is enforced by default.
If you disable the automatic role grant, you must decide which roles to grant to the default service accounts, and then grant these roles yourself.
If the default service account already has the Editor role, we recommend that you replace the Editor role with less permissive roles. To safely modify the service account's roles, use Policy Simulator to see the impact of the change, and then grant and revoke the appropriate roles.
For information about allowing other users, apps, or projects to access a bucket and its contents, see Setting bucket permissions and Setting object permissions.
Using Cloud Storage with the local development server
The App Engine local development server doesn't emulate Cloud Storage, so all Cloud Storage requests must be sent over the Internet to an actual Cloud Storage bucket.
Pricing, quotas, and limits
There are no bandwidth charges associated with Cloud Storage client library calls to Cloud Storage. However, there are operations charges. In addition, the calls count against your URL fetch quota as the library uses the URL Fetch service to interact with Cloud Storage.
Notice that Cloud Storage is a pay-to-use service; you will be charged according to the Cloud Storage price sheet.