[[["容易理解","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-08-18 (世界標準時間)。"],[[["\u003cp\u003eBefore deploying an API config to an API Gateway, ensure you have configured your development environment, created an API, defined the API, and generated an API config from the definition.\u003c/p\u003e\n"],["\u003cp\u003eGateway IDs must adhere to specific constraints, including a maximum length of 49 characters and the use of only lowercase letters, numbers, or dashes without starting with a dash or containing underscores.\u003c/p\u003e\n"],["\u003cp\u003eDeploying an API config to a gateway generates a unique URL for API access in the \u003ccode\u003egateway.dev\u003c/code\u003e domain, following the format \u003ccode\u003ehttps://GATEWAY_ID-HASH.REGION_CODE.gateway.dev\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe Google Cloud CLI (\u003ccode\u003egcloud\u003c/code\u003e) is used to deploy API configs to gateways, requiring specification of the gateway ID, API ID, config ID, and the desired Google Cloud region, and it will create the gateway if it does not exist.\u003c/p\u003e\n"],["\u003cp\u003eExisting gateways can be updated to deploy a new API config or to change the display name and labels, and they support zero-downtime updates, although some requests may be handled by the previous API config during the update process.\u003c/p\u003e\n"]]],[],null,["# Deploying an API to a gateway\n=============================\n\nPrerequisites\n-------------\n\nBefore you can deploy an API config on API Gateway, 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](/api-gateway/docs/creating-api).\n\n- [Created an API definition](/api-gateway/docs/openapi-overview).\n\n- [Created an API config](/api-gateway/docs/creating-api-config) from your API definition.\n\nGateway ID requirements\n-----------------------\n\nMany of the `gcloud` commands shown below require you to specify the ID of the gateway, in the form: \u003cvar translate=\"no\"\u003eGATEWAY_ID\u003c/var\u003e.\nAPI Gateway enforces the following requirements for the gateway ID:\n\n- Must have a maximum length of 49 characters.\n- Must contain only lowercase letters, numbers, or dashes.\n- Must not start with a dash.\n- Must not contain an underscore.\n\nDefining the endpoint of the deployed API config\n------------------------------------------------\n\nWhen you deploy an API config to a gateway, API Gateway creates a unique\nURL for the gateway in the `gateway.dev` domain. Your API clients then\nuse a URL in the form below to access the deployed API config: \n\n```\nhttps://GATEWAY_ID-HASH.REGION_CODE.gateway.dev\n```\n\nwhere \u003cvar translate=\"no\"\u003eGATEWAY_ID\u003c/var\u003e is the name of the gateway, \u003cvar translate=\"no\"\u003eHASH\u003c/var\u003e is the unique hash code generated when you deployed the API,\nand \u003cvar translate=\"no\"\u003eREGION_CODE\u003c/var\u003e is the code for the [Cloud location](https://cloud.google.com/about/locations) in which you deployed the gateway.\n\nFor example: \n\n```\nhttps://my-gateway-a12bcd345e67f89g0h.uc.gateway.dev\n```\n\nDeploy an API config to a gateway\n---------------------------------\n\nUse the Google Cloud CLI to deploy an API config to a gateway.\nWhen you deploy the API config, you are required to specify the name of the API.\nIf the gateway does not already exist for the API, then this command also creates it.\n\nTo deploy an API config to a gateway:\n\n1. Validate the project ID returned from the following command to make sure that\n the gateway 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 ```\n2. View help for the `gateway create` command:\n\n ```\n gcloud api-gateway gateways create --help\n ```\n3. Run the following command to deploy the API config to the gateway:\n\n ```\n gcloud api-gateway gateways create GATEWAY_ID \\\n --api=API_ID --api-config=CONFIG_ID \\\n --location=GCP_REGION --project=PROJECT_ID\n ```\n\n where:\n - \u003cvar translate=\"no\"\u003eGATEWAY_ID\u003c/var\u003e specifies the ID of the new gateway. If the gateway does not already exist then this command creates it.\n - \u003cvar translate=\"no\"\u003eAPI_ID\u003c/var\u003e specifies the ID of the API Gateway API associated with this gateway.\n - \u003cvar translate=\"no\"\u003eCONFIG_ID\u003c/var\u003e specifies the ID of the API config deployed to the gateway. You must specify an API config when creating a gateway.\n - \u003cvar translate=\"no\"\u003eGCP_REGION\u003c/var\u003e specifies the Cloud location for the deployed gateway.\n\n | **Note:** Allowed values are:\n | - `asia-northeast1`\n | - `australia-southeast1`\n | - `europe-west1`\n | - `europe-west2`\n | - `us-east1`\n | - `us-east4`\n | - `us-central1`\n | - `us-west2`\n | - `us-west3`\n | - `us-west4`\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e specifies the Google Cloud project ID.\n\n As it is creating the gateway, `gcloud` outputs information to the terminal.\n4. On successful completion, you can use the following command to view details about the gateway:\n\n ```\n gcloud api-gateway gateways describe GATEWAY_ID \\\n --location=GCP_REGION --project=PROJECT_ID\n ```\n\n This command returns the following: \n\n ```objective-c\n apiConfig: projects/PROJECT_ID/locations/global/apis/API_ID/configs/CONFIG_ID\n createTime: '2020-02-05T13:44:12.997862831Z'\n defaultHostname: my-gateway-a12bcd345e67f89g0h.uc.gateway.dev\n displayName: GATEWAY_ID\n name: projects/PROJECT_ID/locations/GCP_REGION/gateways/GATEWAY_ID\n serviceAccount:\n email: gateway-111111@222222-tp.iam.gserviceaccount.com\n state: ACTIVE\n updateTime: '2020-02-05T13:45:00.844705087Z'\n ```\n\n Note the value of the `defaultHostname` property. This is the hostname portion of the gateway URL. To access an API config deployed to this gateway, you use a URL in the form:\n\n \u003cbr /\u003e\n\n ```\n https://my-gateway-a12bcd345e67f89g0h.uc.gateway.dev\n ```\n\n \u003cbr /\u003e\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 a gateway:\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 gateway, 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\"\u003eGATEWAY_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 gateway.\n\nListing gateways\n----------------\n\nTo list gateways for a specific project: \n\n```\ngcloud api-gateway gateways list --project=PROJECT_ID\n```\n\nThis command returns output in the form: \n\n```scdoc\nGATEWAY_ID LOCATION DISPLAY_NAME STATE CREATE_TIME UPDATE_TIME\nmy-gateway us-central1 my-gateway ACTIVE 2021-01-07T00:04:19 2022-05-21T00:33:46\n```\n\nTo list gateways for a specific project and region: \n\n```\ngcloud api-gateway gateways list --location=GCP_REGION --project=PROJECT_ID\n```\n\nUse a `filter` expression to list the gateways associated with a specific API: \n\n```\ngcloud api-gateway gateways list \\\n --filter=\"apiConfig:projects/PROJECT_ID/locations/global/apis/API_ID/*\" \\\n --project=PROJECT_ID\n```\n\nOr use this `filter` to list gateways for a specific API config: \n\n```\ngcloud api-gateway gateways list \\\n --filter=\"apiConfig:projects/PROJECT_ID/locations/global/apis/API_ID/configs/CONFIG_ID\" \\\n --project=PROJECT_ID\n```\n\nUse the project, region, and gateway IDs to obtain detailed information about the gateway,\nincluding the identity of the API config deployed to the gateway: \n\n```\ngcloud api-gateway gateways describe GATEWAY_ID \\\n --location=GCP_REGION --project=PROJECT_ID\n```\n\nUpdating a gateway\n------------------\n\nUpdate a gateway to:\n\n- Deploy a different API config to the gateway\n- Update the display name\n- Update the labels\n\nUse the following `gcloud` command to update an existing gateway, where \u003cvar translate=\"no\"\u003eUPDATE_OPTIONS\u003c/var\u003e is replaced with the gateway option flag and value you wish to update: \n\n```\ngcloud api-gateway gateways update GATEWAY_ID \\\n UPDATE_OPTIONS --api=API_ID --location=GCP_REGION --project=PROJECT_ID \n```\n\nFor example, to update the API config deployed to the gateway: \n\n```\ngcloud api-gateway gateways update GATEWAY_ID \\\n --api-config=NEW_CONFIG_ID --api=API_ID --location=GCP_REGION --project=PROJECT_ID \n```\n\nwhere \u003cvar translate=\"no\"\u003eNEW_CONFIG_ID\u003c/var\u003e specifies the new API config to deploy to the gateway.\n| **Note** : There are two important points to keep in mind when updating a gateway with a new API config:\n|\n| - Gateways only support API configs created under the same API. To deploy an API config created under an other API, you must either create a new gateway or use a gateway that already serves configs under the new API.\n| - API Gateway supports a zero-downtime update model, which means your API continues to handle requests during the deployment of the updated API config. However, there is a period of time while the new API config is being deployed when some requests might still be handled by the previous version of the API config. If you have deployed the API config across multiple regions and gateways, you have to redeploy the updated API config in each region separately.\n\nFor a complete list of available update flags and arguments, see the [gcloud api-gateway gateways update](/sdk/gcloud/reference/api-gateway/gateways/update) reference or use the following command to view all update options: \n\n```\ngcloud api-gateway gateways update --help\n```\n\nDeleting a gateway\n------------------\n\nUse the following `gcloud` command to delete an existing gateway: \n\n```\ngcloud api-gateway gateways delete GATEWAY_ID \\\n --location=GCP_REGION --project=PROJECT_ID\n```\n\nWhat's next\n-----------\n\n- [Monitoring your API](/api-gateway/docs/monitoring)\n- [Passing data to and from the backend service](/api-gateway/docs/passing-data)"]]