firebase-tools: `getAppEngineLocation` always returns 'us-central1'

[REQUIRED] Environment info

firebase-tools: 7.1.0

Platform: macOS Mojave 10.14.5, Node v8.15.1

[REQUIRED] Test case

Deploy a cloud functions project (with scheduled functions) with an app engine location set to another region (e.g. europe-west1)

[REQUIRED] Steps to reproduce

firebase deploy --force --only functions --project some_project_id

[REQUIRED] Expected behavior

The function should return the location of the app engine found within context.firebaseConfig. e.g. App engine location set to europe-west1 should return europe-west1

[REQUIRED] Actual behavior

The function returns the default us-central1 value.

[2019-07-12T15:24:13.299Z] Error Context: {
  "body": {
    "error": {
      "code": 400,
      "message": "Location must equal europe-west1 because the App Engine app that is associated with this project is located in europe-west1",
      "status": "INVALID_ARGUMENT"
    }
  },
  "response": {
    "statusCode": 400,
    "body": {
      "error": {
        "code": 400,
        "message": "Location must equal europe-west1 because the App Engine app that is associated with this project is located in europe-west1",
        "status": "INVALID_ARGUMENT"
      }
    },
    "headers": {
      "vary": "X-Origin, Referer, Origin,Accept-Encoding",
      "content-type": "application/json; charset=UTF-8",
      "date": "Fri, 12 Jul 2019 15:24:13 GMT",
      "server": "ESF",
      "cache-control": "private",
      "x-xss-protection": "0",
      "x-frame-options": "SAMEORIGIN",
      "x-content-type-options": "nosniff",
      "alt-svc": "quic=\":443\"; ma=2592000; v=\"46,43,39\"",
      "accept-ranges": "none",
      "transfer-encoding": "chunked"
    },
    "request": {
      "uri": {
        "protocol": "https:",
        "slashes": true,
        "auth": null,
        "host": "cloudscheduler.googleapis.com",
        "port": 443,
        "hostname": "cloudscheduler.googleapis.com",
        "hash": null,
        "search": null,
        "query": null,
        "pathname": "/v1beta1/projects/some_project_id/locations/us-central1/jobs/firebase-schedule-functionName-europe-west1",
        "path": "/v1beta1/projects/some_project_id/locations/us-central1/jobs/firebase-schedule-functionName-europe-west1",
        "href": "https://cloudscheduler.googleapis.com/v1beta1/projects/some_project_id/locations/us-central1/jobs/firebase-schedule-functionName-europe-west1"
      },
      "method": "PATCH"
    }
  }
}

It seems as though the context.firebaseConfig does not have a cloudResourceLocation field (which is being used to identify the AppEngineLocation) so it is always returning undefined. Changing that field to locationId fixed this issue for me.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 4
  • Comments: 18 (4 by maintainers)

Most upvoted comments

@joehan solution from @PatNeedham isn’t working for me, I’m using firebase 7.8.2 and I’ve set region of GCP in Firebase console.

Here’s detailed log:

Error: HTTP Error: 400, Location must equal europe-west1 because the App Engine app that is associated with this project is located in europe-west1
[2020-02-16T07:59:33.631Z] Error Context: {
  "body": {
    "error": {
      "code": 400,
      "message": "Location must equal europe-west1 because the App Engine app that is associated with this project is located in europe-west1",
      "status": "INVALID_ARGUMENT"
    }
  },
  "response": {
    "statusCode": 400,
    "body": {
      "error": {
        "code": 400,
        "message": "Location must equal europe-west1 because the App Engine app that is associated with this project is located in europe-west1",
        "status": "INVALID_ARGUMENT"
      }
    },
    "headers": {
      "vary": "X-Origin, Referer, Origin,Accept-Encoding",
      "content-type": "application/json; charset=UTF-8",
      "date": "Sun, 16 Feb 2020 07:59:33 GMT",
      "server": "ESF",
      "cache-control": "private",
      "x-xss-protection": "0",
      "x-frame-options": "SAMEORIGIN",
      "x-content-type-options": "nosniff",
      "alt-svc": "quic=\":443\"; ma=2592000; v=\"46,43\",h3-Q050=\":443\"; ma=2592000,h3-Q049=\":443\"; ma=2592000,h3-Q048=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000",
      "accept-ranges": "none",
      "transfer-encoding": "chunked"
    },
    "request": {
      "uri": {
        "protocol": "https:",
        "slashes": true,
        "auth": null,
        "host": "cloudscheduler.googleapis.com",
        "port": 443,
        "hostname": "cloudscheduler.googleapis.com",
        "hash": null,
        "search": null,
        "query": null,
        "pathname": "/v1beta1/projects/tt2helper/locations/us-central1/jobs/firebase-schedule-clansCleanCron-us-central1",
        "path": "/v1beta1/projects/tt2helper/locations/us-central1/jobs/firebase-schedule-clansCleanCron-us-central1",
        "href": "https://cloudscheduler.googleapis.com/v1beta1/projects/tt2helper/locations/us-central1/jobs/firebase-schedule-clansCleanCron-us-central1"
      },
      "method": "PATCH"
    }
  }
}

And with .region(‘europe-west1’):

Error: HTTP Error: 400, Location must equal europe-west1 because the App Engine app that is associated with this project is located in europe-west1
[2020-02-16T08:01:03.643Z] Error Context: {
  "body": {
    "error": {
      "code": 400,
      "message": "Location must equal europe-west1 because the App Engine app that is associated with this project is located in europe-west1",
      "status": "INVALID_ARGUMENT"
    }
  },
  "response": {
    "statusCode": 400,
    "body": {
      "error": {
        "code": 400,
        "message": "Location must equal europe-west1 because the App Engine app that is associated with this project is located in europe-west1",
        "status": "INVALID_ARGUMENT"
      }
    },
    "headers": {
      "vary": "X-Origin, Referer, Origin,Accept-Encoding",
      "content-type": "application/json; charset=UTF-8",
      "date": "Sun, 16 Feb 2020 08:01:03 GMT",
      "server": "ESF",
      "cache-control": "private",
      "x-xss-protection": "0",
      "x-frame-options": "SAMEORIGIN",
      "x-content-type-options": "nosniff",
      "alt-svc": "quic=\":443\"; ma=2592000; v=\"46,43\",h3-Q050=\":443\"; ma=2592000,h3-Q049=\":443\"; ma=2592000,h3-Q048=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000",
      "accept-ranges": "none",
      "transfer-encoding": "chunked"
    },
    "request": {
      "uri": {
        "protocol": "https:",
        "slashes": true,
        "auth": null,
        "host": "cloudscheduler.googleapis.com",
        "port": 443,
        "hostname": "cloudscheduler.googleapis.com",
        "hash": null,
        "search": null,
        "query": null,
        "pathname": "/v1beta1/projects/tt2helper/locations/us-central1/jobs/firebase-schedule-clansCleanCron-europe-west1",
        "path": "/v1beta1/projects/tt2helper/locations/us-central1/jobs/firebase-schedule-clansCleanCron-europe-west1",
        "href": "https://cloudscheduler.googleapis.com/v1beta1/projects/tt2helper/locations/us-central1/jobs/firebase-schedule-clansCleanCron-europe-west1"
      },
      "method": "PATCH"
    }
  }
}

@MaffooBristol I heard back from Firebase support after my last comment on this thread, and the response I got helped eliminate the issue:

Thanks for the logs provided. This issue could be caused by your project settings. I have checked your Firebase project, and I noticed that your project’s GCP location was empty (see screenshots). With this, could you try setting the GCP location to ‘us-east4’ and see if issue persists?

image image

On the https://console.firebase.google.com/u/0/project/PROJECT-ID/settings/general/ page - I set it to us-east4 and the Firebase functions deployments have been error-free since then thankfully!

Same here; I don’t even know what change inbetween two deploy but now I get Error: HTTP Error: 400, Location must equal europe-west1 because the App Engine app that is associated with this project is located in europe-west1. Setting region .region('europe-west1')on functions don’t change anything.

Do you guys found a workaround ?

Same exact issue on my end, but with us-east4 instead of europe-west1. Posted on the firebase slack and reached out to the support team, still no resolution. @mbleigh is there any command line argument to include with firebase deploy --only functions to give verbose output that could include some sort of deployment attempt ID, which could then be passed on to the right folks to check internal system logs?

I am having this issue only with .schedule()

This works:

exports.publish = functions
  .region('europe-west1')
  .pubsub
  .topic('test')
  .onPublish(() => {
    console.log('Testing');
    return null;
  });

This does not:

exports.schedule = functions
  .region('europe-west1')
  .pubsub
  .schedule('every 5 minutes')
  .timeZone('europe/london')
  .onRun((context) => {
    console.log('This will be run every 5 minutes!');
    return null;
  });

When I ran it with --debug, you can see some really weird URL formation where it’s combining us-central1 and europe-west1 🤔 https://cloudscheduler.googleapis.com/v1beta1/projects/my-project/locations/us-central1/jobs/firebase-schedule-schedule-europe-west1

Error: HTTP Error: 400, Location must equal europe-west1 because the App Engine app that is associated with this project is located in europe-west1
[2019-10-05T20:53:47.367Z] Error Context: {
  "body": {
    "error": {
      "code": 400,
      "message": "Location must equal europe-west1 because the App Engine app that is associated with this project is located in europe-west1",
      "status": "INVALID_ARGUMENT"
    }
  },
  "response": {
    "statusCode": 400,
    "body": {
      "error": {
        "code": 400,
        "message": "Location must equal europe-west1 because the App Engine app that is associated with this project is located in europe-west1",
        "status": "INVALID_ARGUMENT"
      }
    },
    "headers": {
      "vary": "X-Origin, Referer, Origin,Accept-Encoding",
      "content-type": "application/json; charset=UTF-8",
      "date": "Sat, 05 Oct 2019 20:53:47 GMT",
      "server": "ESF",
      "cache-control": "private",
      "x-xss-protection": "0",
      "x-frame-options": "SAMEORIGIN",
      "x-content-type-options": "nosniff",
      "alt-svc": "quic=\":443\"; ma=2592000; v=\"46,43\",h3-Q048=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000",
      "accept-ranges": "none",
      "transfer-encoding": "chunked"
    },
    "request": {
      "uri": {
        "protocol": "https:",
        "slashes": true,
        "auth": null,
        "host": "cloudscheduler.googleapis.com",
        "port": 443,
        "hostname": "cloudscheduler.googleapis.com",
        "hash": null,
        "search": null,
        "query": null,
        "pathname": "/v1beta1/projects/my-project/locations/us-central1/jobs/firebase-schedule-schedule-europe-west1",
        "path": "/v1beta1/projects/my-project/locations/us-central1/jobs/firebase-schedule-schedule-europe-west1",
        "href": "https://cloudscheduler.googleapis.com/v1beta1/projects/my-project/locations/us-central1/jobs/firebase-schedule-schedule-europe-west1"
      },
      "method": "PATCH"
    }
  }
}

Same here; I don’t even know what change inbetween two deploy but now I get Error: HTTP Error: 400, Location must equal europe-west1 because the App Engine app that is associated with this project is located in europe-west1. Setting region .region('europe-west1')on functions don’t change anything.

Do you guys found a workaround ?

Hey @MaffooBristol, thanks for digging into the codebase on this one and thank you for the PR! Hopefully I can clarify some of the confusion here. That line you found is intentional, though it’s definitely weird looking.

name: `projects/${projectId}/locations/${appEngineLocation}/jobs/firebase-schedule-${functionName}-${region}

AppEngineLocation is the ‘real’ location here. This code deploys a Cloud Scheduler job in your project, and Cloud Scheduler jobs can only be deployed into the same region as your AppEngine. The original error you saw shows this (Error: HTTP Error: 400, Location must equal europe-west1 because the App Engine app that).

Region is the location where your Cloud Function is deployed. We suffix the Cloud Schedule name with this so that we can keep track of which function that schedule is calling. It doesn’t have any effect on where your stuff gets deployed in this context.

The issue you’re running into is that the API we call to figure out your appEngineLocation isn’t returning a value for it, and we default to us-central1. We are looking into why that API is misbehaving here, but for now, I’d recommend trying the solution that @PatNeedham suggested.

I went into the code and edited this line: https://github.com/firebase/firebase-tools/blob/master/src/functionsConfig.js#L53 to be 'europe-west1' and it started working.

Then I found that I could replace the following line in https://github.com/firebase/firebase-tools/blob/master/src/deploy/functions/createOrUpdateSchedulesAndTopics.ts#L58

name: `projects/${projectId}/locations/${appEngineLocation}/jobs/firebase-schedule-${functionName}-${region}`,

with

name: `projects/${projectId}/locations/${region}/jobs/firebase-schedule-${functionName}-${region}`,

…and it works as expected too.

But I’m wondering, what even is it meant to be doing? Why do some parts of the codebase use the app engine location and others use the one specified? In fact in this instance it uses two different region definitions in one line of code.

I’m brand new to this codebase so I don’t know what’s intentional or not, but hopefully this can help shed some further light on this now closed issue.

Am I missing something?

Hi everyone, thanks for reporting and apologies for this issue. We have identified the bug on our end and are working on a fix. Meanwhile, please use firebase-tools <=v7.0.2.

Thanks for everyone’s patience!