您可以在上述 describe 指令的輸出內容中看到標籤,也可以在 list 指令中加入 --format 選項來查看標籤:
gcloud api-gateway api-configs list \
--api=API_ID --project=PROJECT_ID --format="table(name, labels)"
Listing API 設定
如要列出特定專案的 API 設定,請按照下列步驟操作:
gcloud api-gateway api-configs list --project=PROJECT_ID
這項指令會傳回以下內容:
NAME DISPLAY_NAME ROLLOUT_ID STATE CREATE_TIME
projects/PROJECT_ID/locations/global/apis/API_ID/configs/CONFIG_IDCONFIG_ID 2020-02-04r0 ACTIVE 2020-02-04T16:18:02.369859863Z
如要列出專案中特定 API 的 API 設定,請按照下列步驟操作:
gcloud api-gateway api-configs list --api=API_ID --project=PROJECT_ID
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-03 (世界標準時間)。"],[[["\u003cp\u003eBefore creating an API config, you must have prepared your development environment and created an API definition as an OpenAPI spec, and optionally, you may have already created the API.\u003c/p\u003e\n"],["\u003cp\u003eThe API config ID must adhere to specific formatting rules, including a maximum length of 63 characters and the use of only lowercase letters, numbers, and dashes, without starting with a dash or using underscores.\u003c/p\u003e\n"],["\u003cp\u003eCreating an API config involves using the Google Cloud CLI to upload your API definition, specifying the API name, and if the API doesn't exist, the command will also create it, this is done by following through the steps of changing the correct directory, setting the correct project ID, and running the \u003ccode\u003egcloud api-gateway api-configs create\u003c/code\u003e command.\u003c/p\u003e\n"],["\u003cp\u003eAPI configs can be listed, described, and updated, however, updating an API definition requires creating a new API config, as existing configs cannot be modified except for labels and display names.\u003c/p\u003e\n"],["\u003cp\u003eDeleting an API config requires that it is not in use by any deployed gateway, either through deploying a different config or deleting the gateway, then using the \u003ccode\u003egcloud api-gateway api-configs delete\u003c/code\u003e command.\u003c/p\u003e\n"]]],[],null,["# Creating an API config\n======================\n\nPrerequisites\n-------------\n\nBefore you can create an API config, ensure that you have:\n\n- Prepared your development environment as described in [Configuring your development environment](/api-gateway/docs/configure-dev-env).\n\n- [Created an API definition](/api-gateway/docs/openapi-overview) as an OpenAPI spec.\n\n- Optionally created an API as described in [Creating an API](/api-gateway/docs/creating-api). If the API does not already exist, then creating the API config creates it.\n\nAPI config ID requirements\n--------------------------\n\nMany of the `gcloud` commands shown below require you to specify the ID of the API config, in the form: \u003cvar translate=\"no\"\u003eCONFIG_ID\u003c/var\u003e.\nAPI Gateway enforces the following requirements for the API config ID:\n\n- Must have a maximum length of 63 characters.\n- Must contain only lowercase letters, numbers, or dashes.\n- Must not start with a dash.\n- Must not contain an underscore.\n\nCreating an API config\n----------------------\n\nUse the Google Cloud CLI to upload your API definition to create an API config.\nWhen you upload the API definition, you are required to specify the name of the API.\nIf the API does not already exist in API Gateway then this command also creates it.\n| **Note:** API Gateway supports creation of API definitions as OpenAPI specs for all available backend services. API Gateway also supports the use of gRPC service definitions and configurations for gRPC services on Cloud Run.\n\nTo create an API config:\n\n1. Change directory to the directory containing your API definition.\n\n For more on creating the OpenAPI spec for your API definition, see [OpenAPI overview](/api-gateway/docs/openapi-overview)\n and [Quickstart: Deploy an API on API Gateway](/api-gateway/docs/quickstart).\n\n For more on creating a gRPC service definition and configuration for your API definition, see [Configuring a gRPC service](/api-gateway/docs/grpc-service-config)\n and [Getting started with API Gateway and Cloud Run for gRPC](/api-gateway/docs/get-started-cloud-run-grpc).\n2. Validate the project ID returned from the following command to make sure that\n the service isn't created in the wrong project.\n\n ```\n gcloud config list project\n ```\n\n If you need to change the default project, run the following command\n and replace \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with the Google Cloud project ID\n in which you want to create the service:: \n\n ```\n gcloud config set project PROJECT_ID\n ```\n3. View help for the `api-configs create` command:\n\n ```\n gcloud api-gateway api-configs create --help\n ```\n4. Run the following command to create the API config:\n\n ```\n gcloud api-gateway api-configs create CONFIG_ID \\\n --api=API_ID --openapi-spec=API_DEFINITION \\\n --project=PROJECT_ID --backend-auth-service-account=SERVICE_ACCOUNT_EMAIL\n ```\n\n where:\n - \u003cvar translate=\"no\"\u003eCONFIG_ID\u003c/var\u003e specifies the ID of the new API config.\n - \u003cvar translate=\"no\"\u003eAPI_ID\u003c/var\u003e specifies the ID of the API Gateway API associated with this API config. If the API does not already exist then this command creates it.\n - \u003cvar translate=\"no\"\u003eAPI_DEFINITION\u003c/var\u003e specifies the name of the OpenAPI spec containing the API definition.\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e specifies the Google Cloud project ID.\n - \u003cvar translate=\"no\"\u003eSERVICE_ACCOUNT_EMAIL\u003c/var\u003e specifies the service account used to sign tokens for backends with authentication configured. See [Configuring a service account](/api-gateway/docs/configure-dev-env#configuring_a_service_account) for more details.\n\n As it is creating the API and API config, API Gateway outputs\n information to the terminal. This operation may take several minutes to complete as the API config is propagated to downstream systems. Creation of a complex API config could take up to ten minutes to\n complete successfully. While a config is being created, do not attempt to\n create another config for the same API. Only one config may be created\n for any API at a time.\n5. On successful completion, you can use the following command to view details about the new API config:\n\n ```\n gcloud api-gateway api-configs describe CONFIG_ID \\\n --api=API_ID --project=PROJECT_ID\n ```\n\n This command returns the following: \n\n ```scdoc\n createTime: '2020-02-04T18:33:11.882707149Z'\n displayName: CONFIG_ID\n gatewayConfig:\n backendConfig:\n googleServiceAccount: 1111111@developer.gserviceaccount.com\n labels: ''\n name: projects/PROJECT_ID/locations/global/apis/API_ID/configs/CONFIG_ID\n serviceRollout:\n rolloutId: 2020-02-04r2\n state: ACTIVE\n updateTime: '2020-02-04T18:33:12.219323647Z'\n ```\n6. Enable the API using the managed service name of the API. You can find this value in the Managed Service column for your API on the APIs landing page:\n\n \u003cbr /\u003e\n\n ```\n gcloud services enable MANAGED_SERVICE_NAME.apigateway.PROJECT_ID.cloud.goog\n ```\n\n \u003cbr /\u003e\n\n You only have to run this command once when you create the API. If you later modify the API,\n you do not have to rerun the command.\n\nThe Google Cloud CLI takes many options, including those described in the\n[gcloud Reference](/sdk/gcloud/reference). In addition,\nfor API Gateway, you can set the following options when creating an API config:\n\n- `--async`: Return control to the terminal immediately, without waiting for the operation to complete.\n- `--display-name=`\u003cvar translate=\"no\"\u003eNAME\u003c/var\u003e: Specifies the display name of the API config, meaning the name shown in the UI. Do not use spaces in the name. Use hyphens and underscores instead. The default value is \u003cvar translate=\"no\"\u003eCONFIG_ID\u003c/var\u003e.\n- `--labels=`\u003cvar translate=\"no\"\u003eKEY1\u003c/var\u003e`=`\u003cvar translate=\"no\"\u003eVALUE1\u003c/var\u003e`,`\u003cvar translate=\"no\"\u003eKEY2\u003c/var\u003e`=`\u003cvar translate=\"no\"\u003eVALUE2\u003c/var\u003e`,...`: Specifies labels associated with the API config.\n\nFor example: \n\n```\ngcloud api-gateway api-configs create CONFIG_ID \\\n --api=API_ID --openapi-spec=API_DEFINITION \\\n --project=PROJECT_ID --backend-auth-service-account=SERVICE_ACCOUNT_EMAIL \\\n --async --display-name=MyConfig --labels=a=1,b=2\n```\n\nYou can see the labels in the output of the `describe` command shown above, or in the `list` command by including the `--format` option: \n\n```\ngcloud api-gateway api-configs list \\\n --api=API_ID --project=PROJECT_ID --format=\"table(name, labels)\"\n```\n\nListing API configs\n-------------------\n\nTo list API configs for a specific project: \n\n```\ngcloud api-gateway api-configs list --project=PROJECT_ID\n```\n\nThis command returns the following: \n\n```scdoc\nNAME DISPLAY_NAME ROLLOUT_ID STATE CREATE_TIME\nprojects/PROJECT_ID/locations/global/apis/API_ID/configs/CONFIG_ID CONFIG_ID 2020-02-04r0 ACTIVE 2020-02-04T16:18:02.369859863Z\n```\n\nTo list API configs for a specific API in a project: \n\n```\ngcloud api-gateway api-configs list --api=API_ID --project=PROJECT_ID\n```\n\nUse the project, API, and config IDs to obtain detailed information about the API config: \n\n```\ngcloud api-gateway api-configs describe CONFIG_ID \\\n --api=API_ID --project=PROJECT_ID\n```\n\nUpdating an API config\n----------------------\n\nYou cannot modify an existing API config other than to update its labels and its display name.\n| **Note:** Every time you upload an API definition, API Gateway creates a new API config.\n|\n| To update an API definition:\n|\n| 1. Update the OpenAPI spec containing the API definition.\n| 2. Upload the API definition to create a **new** API config.\n|\n| Use the same command to create the **new** API config as you used to create the initial API config,\n| as shown above in [Creating an API config](#creating-an-api-config).\n\nUse the following `gcloud` to update an existing API config:\n\n- `--display-name`\n- `--update-labels`\n- `--clear-labels`\n- `--remove-labels`\n\nFor example: \n\n```\ngcloud api-gateway api-configs update CONFIG_ID \\\n --api=API_ID --project=PROJECT_ID \\\n --update-labels=a=1,b=2\n```\n\nUse the following command to view all update options: \n\n```\ngcloud api-gateway api-configs update --help\n```\n\nDeleting an API config\n----------------------\n\n| **Warning:** If you deployed the API config to a gateway, the API config may not be deleted until the gateway is no longer using that API config.\n|\n| Before you delete an API config that is in use, you must either:\n|\n| - Deploy a different API config to the gateway.\n| - Delete the gateway.\n|\n| See [Deploying an API to a gateway](/api-gateway/docs/deploying-api) for more.\n\nUse the following `gcloud` command to delete an existing API config: \n\n```\ngcloud api-gateway api-configs delete CONFIG_ID --api=API_ID --project=PROJECT_ID\n```\n\nWhat's next\n-----------\n\n- [Deploying an API to a gateway](/api-gateway/docs/deploying-api)"]]