Como usar o ambiente flexível do App Engine em uma rede VPC compartilhada
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
No ambiente flexível do App Engine, é possível especificar uma rede em que as instâncias de seu serviço serão implantadas. Nesta página, você aprende a configurar seu projeto para usar o ambiente flexível do App Engine em uma rede VPC compartilhada.
Para mais informações sobre como configurar uma rede VPC compartilhada, consulte esta página.
Como configurar o ambiente flexível do App Engine com uma VPC compartilhada
A implantação de instâncias do ambiente flexível do App Engine em uma rede VPC compartilhada envolve três etapas:
Se você usar a Google Cloud CLI, atualize para a versão mais recente
antes de seguir este guia executando o comando:
gcloud components update
Como permitir tráfego para a rede VPC compartilhada
Para permitir o tráfego para o ambiente flexível do App Engine na rede VPC compartilhada, um administrador dessa rede precisa criar uma regra de firewall no projeto host da VPC. A regra de firewall permite veicular o tráfego para instâncias do ambiente flexível, além de verificar a integridade dele.
A regra de firewall precisa ter as seguintes propriedades:
Rede: o nome da rede VPC compartilhada
Direção do tráfego: entrada
Ação na correspondência: permitir
Destinos: tags de destino especificadas
Tags de meta: aef-instance
Filtro de origem: intervalos de IP
Intervalos de IPs de origem: 35.191.0.0/16, 130.211.0.0/22
Protocolos e portas: protocolos e portas especificados
TCP: 8443, 10402
Um administrador de VPC compartilhada pode criar a regra de firewall usando o console Google Cloud
ou a Google Cloud CLI:
Console
Para criar a regra de firewall usando o console do Google Cloud :
HOST_PROJECT_ID é o ID do projeto Google Cloud
do projeto host da VPC compartilhada.
Configurando as permissões
Um administrador de VPC compartilhada precisa conceder às duas contas de serviço a seguir
o papel de usuário da rede do Compute para
permitir que um projeto de serviço implante instâncias no ambiente flexível do App Engine
para a rede:
Agente de serviço do Google APIs
(PROJECT_NUM@cloudservices.gserviceaccount.com)
Agente de serviço do ambiente flexível do App Engine
(service-PROJECT_NUM@gae-api-prod.google.com.iam.gserviceaccount.com)
Console
Para configurar permissões usando o console Google Cloud :
Acesse a página "Configurações" do IAM referente ao projeto do serviço e anote o número do projeto.
Na lista suspensa Selecionar um papel, selecione Compute Engine > Usuário da rede do Compute.
Clique em Salvar.
gcloud
Consiga o número do projeto de serviço em que o aplicativo do App Engine está implantado. Execute o seguinte comando, substituindo SERVICE_PROJECT_ID pelo ID do projeto de serviço:
Depois de configurar a regra de firewall e as permissões adequadas, implante um serviço novo ou atual no ambiente flexível do App Engine na rede VPC compartilhada.
No arquivo app.yaml, use o campo configurações de rede name para especificar o nome completo da rede do Shared VPC:
Para verificar se o serviço de ambiente flexível do App Engine
está em execução na rede VPC compartilhada, confira a configuração da versão
na página de versões do App Engine no
consoleGoogle Cloud :
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-08-11 UTC."],[[["\u003cp\u003eThe App Engine flexible environment can be deployed on a Shared VPC network by configuring the host project and service project appropriately.\u003c/p\u003e\n"],["\u003cp\u003eA Shared VPC Admin must create a firewall rule in the Shared VPC host project to allow ingress traffic on specific IP ranges and ports to the App Engine flexible environment, which should be tagged with \u003ccode\u003eaef-instance\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eTwo service accounts, the Google APIs service agent and the App Engine flexible environment service agent, must be granted the Compute Network User role in the Shared VPC host project by a Shared VPC Admin.\u003c/p\u003e\n"],["\u003cp\u003eTo deploy an App Engine flexible environment service to a Shared VPC network, the \u003ccode\u003eapp.yaml\u003c/code\u003e file must be configured with the fully-qualified name of the Shared VPC network and optionally a subnetwork name.\u003c/p\u003e\n"],["\u003cp\u003eAfter deployment, the network configuration can be verified on the App Engine versions page in the Google Cloud Console by checking the config column for the desired version.\u003c/p\u003e\n"]]],[],null,["# Using the App Engine flexible environment on a Shared VPC network\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nIn the App Engine flexible environment, you can specify a network\nto deploy your service's instances on. This page shows you how to configure\nyour project to use the App Engine flexible environment on\na Shared VPC network.\n\nSee [Provisioning Shared VPC](/vpc/docs/provisioning-shared-vpc) for more\ninformation about setting up a Shared VPC network.\n\nSetting up the App Engine flexible environment with Shared VPC\n--------------------------------------------------------------\n\nDeploying App Engine flexible environment instances on a\nShared VPC network involves three steps:\n\n1. [Create a firewall rule to allow App Engine flexible\n environment traffic on the Shared VPC network](#allowing-traffic)\n\n2. [Grant appropriate permissions to service accounts in the Shared VPC service project](#setting_up_permissions)\n\n3. [Configure your App Engine services to use the Shared VPC network](#configuring-deploying)\n\nIf you use the Google Cloud CLI, update to the latest\nversion before following this guide by running the command: \n\n gcloud components update\n\n### Allowing traffic to the Shared VPC network\n\nA Shared VPC Admin needs to create a firewall rule in the Shared VPC host\nproject in order to allow traffic to the App Engine flexible\nenvironment on the Shared VPC network. The firewall rule allows serving and\nhealth check traffic to flexible environment instances.\n\nThe firewall rule must have the following properties:\n\n- **Network**: The name of the Shared VPC network\n- **Direction of traffic**: Ingress\n- **Action on match**: Allow\n- **Targets**: Specified target tags\n- **Target tags** : `aef-instance`\n- **Source filter**: IP ranges\n- **Source IP ranges** : `35.191.0.0/16`, `130.211.0.0/22`\n- **Protocols and ports** : Specified protocols and ports\n - **tcp**: 8443, 10402\n\nA Shared VPC Admin can create the firewall rule using the Google Cloud console\nor the Google Cloud CLI: \n\n### Console\n\nTo create the firewall rule using the Google Cloud console:\n\n1. Go to the firewall rule creation page.\n\n [Create a firewall rule](https://console.cloud.google.com/networking/firewalls/add)\n2. In the **Name** and **Description** fields, provide a name and\n description for the firewall rule.\n\n3. Fill in the necessary properties as specified above.\n\n4. Click **Create**.\n\n### gcloud\n\nTo create the firewall rule using the Google Cloud CLI,\nrun the following command: \n\n```sh\ngcloud compute firewall-rules create NETWORK_NAME-flex-firewall \\\n--project HOST_PROJECT_ID \\\n--network NETWORK_NAME \\\n--allow tcp:10402,tcp:8443 \\\n--target-tags aef-instance \\\n--source-ranges 35.191.0.0/16,130.211.0.0/22 \\\n--description 'Allows traffic to App Engine flexible environment'\n```\n\nwhere:\n\n- \u003cvar translate=\"no\"\u003eNETWORK_NAME\u003c/var\u003e is the name of the Shared VPC network.\n- \u003cvar translate=\"no\"\u003eHOST_PROJECT_ID\u003c/var\u003e is the Google Cloud project ID of the Shared VPC host project.\n\n### Setting up permissions\n\nA Shared VPC Admin must grant the following two service accounts\nthe [Compute Network User](/compute/docs/access/iam#compute.networkUser) role\nin order to allow a service project to deploy instances in the App Engine flexible environment\nto the network:\n\n- Google APIs service agent (\u003cvar translate=\"no\"\u003ePROJECT_NUM\u003c/var\u003e`@cloudservices.gserviceaccount.com`)\n- App Engine flexible environment service agent (`service-`\u003cvar translate=\"no\"\u003ePROJECT_NUM\u003c/var\u003e`@gae-api-prod.google.com.iam.gserviceaccount.com`)\n\n**Note:** App Engine creates the App Engine flexible environment service agent (`service-`\u003cvar translate=\"no\"\u003ePROJECT_NUM\u003c/var\u003e`@gae-api-prod.google.com.iam.gserviceaccount.com`) when you deploy your first app to the flexible environment. You can verify if the service agent exists in your project by following [these steps](/appengine/docs/flexible/service-agent#verifying_the_service_agent). \n\n### Console\n\nTo set up permissions using the Google Cloud console:\n\n1. Go to the IAM Settings page for the **service project**\n and take note of the **Project number**.\n\n [Go to IAM Settings](https://console.cloud.google.com/iam-admin/settings)\n2. Go to the IAM page for the **host project**.\n\n [Go to IAM](https://console.cloud.google.com/iam-admin/iam)\n3. Click **Add**.\n\n4. In the **New members** field, enter the following email addresses\n separated by a comma. Replace \u003cvar translate=\"no\"\u003ePROJECT_NUM\u003c/var\u003e\n with the project number obtained in step 1.\n\n - \u003cvar translate=\"no\"\u003ePROJECT_NUM\u003c/var\u003e`@cloudservices.gserviceaccount.com`\n - `service-`\u003cvar translate=\"no\"\u003ePROJECT_NUM\u003c/var\u003e`@gae-api-prod.google.com.iam.gserviceaccount.com`\n5. In the **Select a role** dropdown, select **Compute Engine** \\\u003e **Compute Network User**.\n\n6. Click **Save**.\n\n### gcloud\n\n1. Get the project number of the service project where the\n App Engine app is deployed. Run the following command,\n replacing \u003cvar translate=\"no\"\u003eSERVICE_PROJECT_ID\u003c/var\u003e with the\n project ID of the service project:\n\n ```sh\n export SERVICE_PROJECT_NUM=$(gcloud projects describe SERVICE_PROJECT_ID --format=\"value(projectNumber)\")\n ```\n2. Grant the service project's Google APIs Service Agent the\n `compute.networkUser` role in the host project:\n\n ```sh\n gcloud projects add-iam-policy-binding HOST_PROJECT_ID \\\n --member=serviceAccount:$SERVICE_PROJECT_NUM@cloudservices.gserviceaccount.com \\\n --role=roles/compute.networkUser\n ```\n\n where \u003cvar translate=\"no\"\u003eHOST_PROJECT_ID\u003c/var\u003e is the\n Google Cloud project ID of the Shared VPC host project.\n3. Grant the service project's App Engine Flexible Environment\n Service Agent the `compute.networkUser` role in the host project:\n\n ```sh\n gcloud projects add-iam-policy-binding HOST_PROJECT_ID \\\n --member=serviceAccount:service-$SERVICE_PROJECT_NUM@gae-api-prod.google.com.iam.gserviceaccount.com \\\n --role=roles/compute.networkUser\n ```\n\n### Configuring and deploying your service\n\nAfter the firewall rule and proper permissions are set up, you can deploy\neither a new service or an existing App Engine flexible environment\nservice to the Shared VPC network.\n\n1. In the `app.yaml` file, use the\n [network settings](/appengine/docs/flexible/reference/app-yaml#network_settings)\n `name` field to specify the fully-qualified name of the Shared VPC network:\n\n ```\n network:\n name: projects/HOST_PROJECT_ID/global/networks/NETWORK_NAME\n ```\n\n where\n - \u003cvar translate=\"no\"\u003eHOST_PROJECT_ID\u003c/var\u003e is the Google Cloud project ID of the Shared VPC host project.\n - \u003cvar translate=\"no\"\u003eNETWORK_NAME\u003c/var\u003e is the name of the Shared VPC network.\n\n To configure the service to be part of a subnetwork named\n \u003cvar translate=\"no\"\u003eSUBNETWORK_NAME\u003c/var\u003e, also set the `subnetwork_name`\n field: \n\n ```\n network:\n name: projects/HOST_PROJECT_ID/global/networks/NETWORK_NAME\n subnetwork_name: SUBNETWORK_NAME\n ```\n2. Deploy the service:\n\n ```\n gcloud app deploy\n ```\n\n \u003cbr /\u003e\n\nVerifying your configuration\n----------------------------\n\nTo verify that your App Engine flexible environment\nservice is running on the Shared VPC network, view the version\nconfiguration on the App Engine versions page in the\nGoogle Cloud console:\n\n1. Go to the App Engine Versions page.\n\n [Go to App Engine versions](https://console.cloud.google.com/appengine/versions)\n2. In the **Config** column on the right, click on **View** for\n the desired version.\n\n3. Verify that the network name in the configuration is the name of\n the Shared VPC network."]]