Firebase云函数新手求助:如何升级GCP旧版元数据服务器端点?
Hey there! Let's walk through how to resolve this metadata server endpoint issue step by step—no need to stress, it's simpler than it sounds.
First: Check for Direct Requests to Old Endpoints
Looking at your provided function code, you don't have any direct HTTP requests to the metadata server (like calling http://metadata.google.internal/v0.1/... or v1beta1 endpoints directly). All your logic uses the official firebase-admin and firebase-functions SDKs, so you can ignore the "direct request upgrade steps" mentioned in Google's email—those don't apply to your code.
Second: Upgrade Your Firebase SDK Dependencies
The issue is likely coming from older versions of the Firebase SDKs, which might use underlying libraries that call the deprecated metadata endpoints. Your current versions (firebase-admin@8.0.0 and firebase-functions@3.2.0) are a bit outdated, and newer versions have already switched to the v1 metadata endpoint. Here's how to upgrade:
- Open your project's terminal, navigate to the
functionsdirectory. - Run this command to install the latest stable versions of the SDKs:
npm install firebase-admin@latest firebase-functions@latest --save - Once the installation finishes, re-deploy your cloud functions to apply the changes:
firebase deploy --only functions
Optional: Simplify Admin Initialization
In newer SDK versions, you can simplify the admin initialization code. Instead of:
admin.initializeApp(functions.config().firebase);
You can use:
admin.initializeApp();
The old syntax still works, but the new one is cleaner and uses default project settings automatically.
Why This Works
Upgrading the SDKs ensures that all internal calls to Google's metadata server use the v1 endpoint (the only supported version after April 30, 2020). Your core business logic (sending push notifications via Realtime Database triggers) doesn't need any changes—all the endpoint handling happens under the hood in the SDK.
After upgrading and re-deploying, your functions will no longer trigger the deprecated endpoint warnings, and you'll be compliant with Google's requirements.
内容的提问来源于stack exchange,提问作者Dan Abnormal

