Reputation: 31
Everything works correctly when I deploy my functions, but running the same code locally with the Firebase emulator gives me the following error:
{
"message": "Unexpected error determining execution environment: request to http://169.254.169.254/computeMetadata/v1/instance failed, reason: connect EHOSTDOWN 169.254.169.254:80 - Local (192.168.1.101:56456)",
"type": "system",
"errno": "EHOSTDOWN",
"code": "EHOSTDOWN",
"config": {
"url": "http://169.254.169.254/computeMetadata/v1/instance",
"headers": {
"Metadata-Flavor": "Google"
},
"retryConfig": {
"noResponseRetries": 0,
"currentRetryAttempt": 0,
"retry": 3,
"retryDelay": 100,
"httpMethodsToRetry": [
"GET",
"HEAD",
"PUT",
"OPTIONS",
"DELETE"
],
"statusCodesToRetry": [
[
100,
199
],
[
429,
429
],
[
500,
599
]
]
},
"responseType": "text",
"timeout": 3000,
"params": {},
"method": "GET"
}
}
What should I do to be able to test my code with the emulator?
Upvotes: 2
Views: 2047
Reputation: 111
If your cloud function requires admin rights, then you need to configure a service account for the cloud functions to run under.
Follow the instructions here: https://firebase.google.com/docs/admin/setup
1) Create a Service Account and download the .json private key files (keep this secret)
In the console where you will run your emulator:
2) Set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the absolute path of the private key file saved in step 1. For example export GOOGLE_APPLICATION_CREDENTIALS="/Users/..../...account.json"
3) Now run your emulator firebase emulators:start --only functions
Now the locally emulated function knows the environment. So when you do something like admin.initializeApp(functions.config().firebase);
it gets configured properly.
Upvotes: 1