Default GCS token name

According to https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/activate :

The default bucket name is usually <app_id> .appspot.com, where you will replace your app ID. You can find the bucket name in the App Engine app drawer under the App Settings tab under the Google Cloud Storage Bucket tag. Alternatively, you can use the get_default_gcs_bucket_name () Authentication Method application to determine the name programmatically.

When I look under the Google Cloud Storage Bucket table I can see <app-id>.appspot.com

where <app-id>

is my App ID. This is similar to the first two sentences in the previous paragraph.

But when I call get_default_gcs_bucket_name()

, as suggested in the last sentence, the return value is app_default_bucket

.

Since I am deploying this application across multiple sites, I would like to use a method call. Is there a way I can get this to return the real bucket name to the default?

+2


source to share


2 answers


Most services are stubbed out in the development environment. After deploying the app to GAE, get_default_gcs_bucket_name will return <app_id>.appspot.com

.

I have tested the behavior in the following application:



import webapp2

from google.appengine.api import app_identity


class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write(app_identity.get_default_gcs_bucket_name())

application = webapp2.WSGIApplication([
    ('/', MainPage),
], debug=True)

      

+3


source


You can use the client library with a development server. However, since there is no local emulation of cloud storage, all read and write file requests must be sent over the Internet to the actual cloud storage.

To use the client library with the development app server:

Activate Cloud Storage.



Run dev_appserver.py with the --default_gcs_bucket_name [BUCKET_NAME] flag , replacing [BUCKET_NAME] with the name of the cloud storage you are using.

This flag controls the bucket that will be returned when your application calls file.DefaultBucketName (ctx).

This can be found in Google Docs - https://cloud.google.com/appengine/docs/standard/python/googlecloudstorageclient/setting-up-cloud-storage#activating_a_cloud_storage_bucket

0


source







All Articles