skip to Main Content

I’m trying to deploy a Firestore 2nd gen functions with command firebase deploy --only functions but I got a error:


There was an issue deploying your functions. Verify that your project has a Google App Engine instance setup at https://console.cloud.google.com/appengine and try again. If this issue persists, please contact support.
⚠  functions: Upload Error: HTTP Error: 400, Could not create bucket gcf-v2-uploads-758827227995-us-central1. 'us-central1' violates constraint 'constraints/gcp.resourceLocations'

Error: HTTP Error: 400, Could not create bucket gcf-v2-uploads-758827227995-us-central1. 'us-central1' violates constraint 'constraints/gcp.resourceLocations'

According with a [documentation] (https://firebase.google.com/docs/functions/locations#best_practices_for_changing_region) use just:

exports.myStorageFunction = functions
    .region('europe-west1')
    .storage
    .object()
    .onFinalize((object) => {
      // ...
    });

How I can do in Python? my function was written in Python.

2

Answers


  1. use the region property in the firebase.functions.config()

    import firebase
    
    firebase_admin = firebase.initialize_app()
    
    functions = firebase_admin.functions
    
    config = functions.config()
    
    config.region = "us-central1"
    

    This will deploy your function to the us-central1 region. You can also use the location property to deploy your function to a specific location within a region

    config.location = "us-central1-a"
    
    • This will deploy your function to the us-central1-a location.
    • The default region for Firestore 2nd gen functions is us-central1. If
      you do not specify a region, your function will be deployed to this
      region.
    Login or Signup to reply.
  2. Using this documentation as reference, you can define runtime options in the arguments of functions decorator. If you’re trying to set the region for a Firebase Cloud Function written in Python, you can try specifying the region in the functions decorator like so:

    from firebase_functions import https_fn
    
    @https_fn.on_request(region='asia-east1')
    # @https_fn.on_request()
    def on_request_example(req: https_fn.Request) -> https_fn.Response:
        return https_fn.Response("Hello world!")
    

    If you’re configuring a Cloud Firestore trigger(e.g. on_document_created), it would look like:

    from firebase_functions.firestore_fn import (
        on_document_created,
        Event,
        DocumentSnapshot,
    )
    
    
    @on_document_created(document="users/{userId}", region="asia-east1")
    def userCreated(event: Event[DocumentSnapshot]) -> None:
        new_value = event.data.to_dict()
        name = new_value["name"]
        print(name)
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search