Python 2.7 はサポートが終了しており、2026 年 1 月 31 日に
非推奨になります。非推奨になると、過去に組織のポリシーを使用して以前のランタイムのデプロイを再度有効にしていた場合でも、Python 2.7 アプリケーションをデプロイできなくなります。既存の Python 2.7 アプリケーションは、
非推奨日以降も引き続き実行され、トラフィックを受信します。
サポートされている最新バージョンの Python に移行することをおすすめします。
共有 VPC サービス プロジェクトでコネクタを構成する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
組織で共有 VPC を使用している場合は、サーバーレス VPC アクセス コネクタをサービス プロジェクトまたはホスト プロジェクトのいずれかで設定できます。このガイドでは、サービス プロジェクトでコネクタを設定する方法について説明します。
ホスト プロジェクトでコネクタを設定する必要がある場合は、ホスト プロジェクトでコネクタを構成するをご覧ください。各方法の利点については、共有 VPC ネットワークへの接続をご覧ください。
大まかには、次の手順を行う必要があります。
- 必要な IP 範囲を許可するファイアウォール ルールを追加する
- 権限を付与する
- サブネットを作成する
- サーバーレス VPC アクセスの構成ページの次のセクションの手順を完了します。
始める前に
サーバーレス VPC アクセスは、URL 取得サービスに対応していません。開始前に、URL 取得のデフォルトを無効にし、urlfetch
ライブラリの明示的な使用を中止します。
IP 範囲を許可するファイアウォール ルールを追加する
この手順を行うには、ホスト プロジェクトで次のいずれかのロールが必要です。
次の IP 範囲からのリクエストを許可してコネクタに到達し、コネクタからも到達できるように、ファイアウォール ルールを作成する必要があります。
- NAT 範囲
107.178.230.64/26
35.199.224.0/19
- ヘルスチェック範囲
130.211.0.0/22
35.191.0.0/16
108.170.220.0/23
これらの範囲は、Cloud Run、Cloud Run functions、App Engine スタンダード環境の基盤となる Google インフラストラクチャで使用されます。これらの IP からのすべてのリクエストは Google インフラストラクチャから送信されるため、Cloud Run、Cloud Run functions、App Engine のサービス / 関数 / アプリはそれぞれ接続先の VPC コネクタとのみ通信します。
単純な構成の場合、共有 VPC ネットワークに接続されているすべてのサービス プロジェクトが、サーバーレス サービスがネットワーク内の任意のリソースにリクエストを送信できるように、ルールを適用します。
これらのルールを適用するには:
次の 3 つのコマンドを実行して、サーバーレス環境からのリクエストがネットワーク内のすべての VPC コネクタに到達できるようにするルールを設定します。
gcloud compute firewall-rules create serverless-to-vpc-connector \
--allow tcp:667,udp:665-666,icmp \
--source-ranges 107.178.230.64/26,35.199.224.0/19 \
--direction=INGRESS \
--target-tags vpc-connector \
--network=VPC_NETWORK
gcloud compute firewall-rules create vpc-connector-to-serverless \
--allow tcp:667,udp:665-666,icmp \
--destination-ranges 107.178.230.64/26,35.199.224.0/19 \
--direction=EGRESS \
--target-tags vpc-connector \
--network=VPC_NETWORK
gcloud compute firewall-rules create vpc-connector-health-checks \
--allow tcp:667 \
--source-ranges 130.211.0.0/22,35.191.0.0/16,108.170.220.0/23 \
--direction=INGRESS \
--target-tags vpc-connector \
--network=VPC_NETWORK
VPC_NETWORK
は、コネクタを接続する VPC ネットワークです。
VPC ネットワーク上で、コネクタからのリクエストを許可する上り(内向き)ルールを作成します。
gcloud compute firewall-rules create vpc-connector-requests \
--allow tcp,udp,icmp \
--direction=INGRESS \
--source-tags vpc-connector \
--network=VPC_NETWORK
このルールにより、VPC コネクタに対して、ネットワーク内のすべてのリソースへのアクセスが許可されます。サーバーレス VPC アクセスを使用してサーバーレス環境でアクセスできるリソースを制限するには、これらのファイアウォール ルールのターゲットを指定します。
特定のコネクタに対するファイアウォール ルールを作成する
IP 範囲を許可するファイアウォール ルールを追加するの手順に沿って、既存のコネクタと、今後作成されるコネクタの両方すべてに適用されるファイアウォール ルールを作成します。これが必要でなく、特定のコネクタだけに対するルールを作成する場合は、それらのコネクタにのみ適用されるようにルールの範囲を設定できます。
ルールの対象範囲を特定のコネクタに限定するには、次のいずれかの仕組みを使用できます。
- ネットワーク タグ。各コネクタには、
vpc-connector
と vpc-connector-REGION-CONNECTOR_NAME
の 2 つのネットワーク タグがあります。後者のフォーマットを使用して、ファイアウォール ルールの範囲を特定のコネクタに制限します。
- IP 範囲。このルールは Ingress で機能しないため、下り(外向き)ルールにのみ使用します。コネクタ サブネットの IP 範囲を使用して、ファイアウォール ルールの範囲を単一の VPC コネクタに制限できます。
サービス プロジェクトのサービス アカウントに権限を付与する
共有 VPC 管理者は、VPC コネクタを使用する各サービス プロジェクトについて、ホスト プロジェクトでの Compute ネットワーク ユーザー ロール(compute.networkUser
)をサービス プロジェクト cloudservices
と vpcaccess
サービス アカウントに付与する必要があります。
ロールを付与するには:
次のコマンドを使用します。
gcloud projects add-iam-policy-binding HOST_PROJECT_ID \
--role "roles/compute.networkUser" \
--member "serviceAccount:service-SERVICE_PROJECT_NUMBER@gcp-sa-vpcaccess.iam.gserviceaccount.com"
gcloud projects add-iam-policy-binding HOST_PROJECT_ID \
--role "roles/compute.networkUser" \
--member "serviceAccount:SERVICE_PROJECT_NUMBER@cloudservices.gserviceaccount.com"
@gcp-sa-vpcaccess
サービス アカウントが存在しない場合は、サービス プロジェクトでサーバーレス VPC アクセス API を有効にしてから、もう一度お試しください。
gcloud services enable vpcaccess.googleapis.com
これらのサービス アカウントに共有 VPC ネットワーク全体へのアクセスを許可せず、特定のサブネットにのみアクセス権を付与する場合は、代わりにこれらのロールを特定のサブネット上のサービス アカウントのみに付与することもできます。
サブネットを作成する
共有 VPC を使用する場合、共有 VPC 管理者はコネクタごとにサブネットを作成する必要があります。サブネットの追加の説明に沿って、共有 VPC ネットワークに /28
サブネットを追加します。このサブネットは、コネクタを使用するサーバーレス サービスと同じリージョンに存在する必要があります。
次のステップ
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-09-04 UTC。
[[["わかりやすい","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-04 UTC。"],[[["\u003cp\u003eThis guide outlines how to set up Serverless VPC Access connectors in a service project when using Shared VPC, offering an alternative to setting up connectors in the host project.\u003c/p\u003e\n"],["\u003cp\u003eBefore setting up, users must disable the URL Fetch default and any explicit use of the \u003ccode\u003eurlfetch\u003c/code\u003e library, as Serverless VPC Access is incompatible with the URL Fetch service.\u003c/p\u003e\n"],["\u003cp\u003eSetting up firewall rules is required to allow requests from specific IP ranges to reach and be reached by the connector, with options to apply these rules to all connectors or specific ones using network tags or IP ranges.\u003c/p\u003e\n"],["\u003cp\u003eShared VPC Admins must grant the Compute Network User role to the service project's \u003ccode\u003ecloudservices\u003c/code\u003e and \u003ccode\u003evpcaccess\u003c/code\u003e service accounts, and if preferred, these roles can be granted on specific subnets only.\u003c/p\u003e\n"],["\u003cp\u003eA subnet, specifically a \u003ccode\u003e/28\u003c/code\u003e subnet, must be created by the Shared VPC Admin for each connector, ensuring it is located in the same region as the serverless services.\u003c/p\u003e\n"]]],[],null,["# Configure connectors in Shared VPC service projects\n\nIf your organization uses Shared VPC, you can set up\nServerless VPC Access connectors in either the service project or the\nhost project. This guide shows how to set up a connector in the service project.\n\nIf you need to set up a connector in the host project, see\n[Configure connectors in the host project](/appengine/docs/legacy/standard/python/shared-vpc-host-project).\nTo learn about the advantages of each method, see\n[Connecting to a Shared VPC network](/appengine/docs/legacy/standard/python/connecting-shared-vpc).\n\nAt a high level, you must take the following steps:\n\n1. [Add firewall rules to allow required IP ranges](#firewall-rules-shared-vpc)\n2. [Grant permissions](#grant-permissions)\n3. [Create a subnet](#subnet)\n4. In the page [Configuring Serverless VPC Access](/vpc/docs/configure-serverless-vpc-access), complete the steps in the following sections:\n - [Create a Serverless VPC Access connector](/vpc/docs/configure-serverless-vpc-access#create-connector)\n - [Configure your serverless environment to use a connector](/vpc/docs/configure-serverless-vpc-access#configure-environment)\n\n\u003cbr /\u003e\n\nBefore you begin\n----------------\n\n\u003cbr /\u003e\n\nServerless VPC Access is not compatible with the URL Fetch\nservice. Before you begin,\n[disable the URL Fetch default](/appengine/docs/legacy/standard/python/sockets#making_httplib_use_sockets)\nand discontinue any explicit use of the\n[`urlfetch`](/appengine/docs/legacy/standard/python/refdocs/google.appengine.api.urlfetch)\nlibrary.\n\nAdd firewall rules to allow IP ranges\n-------------------------------------\n\nTo perform these steps, you must have one of the following roles on the\nhost project:\n\n- Compute Engine [Security Admin](/compute/docs/access/iam#compute.securityAdmin) role\n- Custom [Identity and Access Management (IAM)](/iam) role with the [`compute.firewalls.create`](/compute/docs/reference/rest/v1/firewalls/insert#iam-permissions) permission enabled\n\nYou must create firewall rules to allow requests from the following IP ranges to\nreach the connector and to be reached by the connector:\n\n- NAT ranges\n - `107.178.230.64/26`\n - `35.199.224.0/19`\n- Health check ranges\n - `130.211.0.0/22`\n - `35.191.0.0/16`\n - `108.170.220.0/23`\n\nThese ranges are used by the Google infrastructure underlying Cloud Run,\nCloud Run functions, and the App Engine standard environment. All requests from these IPs are guaranteed\nto originate from Google infrastructure, which ensures that each\nCloud Run, Cloud Run functions, and App Engine service/function/app\nonly communicates with the VPC Connector it is connected to.\n\nFor a simple configuration, apply the rules to allow serverless services in any\nservice project connected to the Shared VPC network to send requests to\nany resource in the network.\n| **Important:** The rules you create using the following process apply to existing and future connectors. If you want to scope these rules so they only apply to specified connectors, see [Create firewall rules with narrower scope](#narrow-scope-rules).\n\nTo apply these rules:\n\n1. Run the following three commands to set the rules to allow requests from the\n serverless environment to reach all VPC Connectors in the network:\n\n ```bash\n gcloud compute firewall-rules create serverless-to-vpc-connector \\\n --allow tcp:667,udp:665-666,icmp \\\n --source-ranges 107.178.230.64/26,35.199.224.0/19 \\\n --direction=INGRESS \\\n --target-tags vpc-connector \\\n --network=VPC_NETWORK\n ``` \n\n ```bash\n gcloud compute firewall-rules create vpc-connector-to-serverless \\\n --allow tcp:667,udp:665-666,icmp \\\n --destination-ranges 107.178.230.64/26,35.199.224.0/19 \\\n --direction=EGRESS \\\n --target-tags vpc-connector \\\n --network=VPC_NETWORK\n ``` \n\n ```bash\n gcloud compute firewall-rules create vpc-connector-health-checks \\\n --allow tcp:667 \\\n --source-ranges 130.211.0.0/22,35.191.0.0/16,108.170.220.0/23 \\\n --direction=INGRESS \\\n --target-tags vpc-connector \\\n --network=VPC_NETWORK\n ```\n\n Where \u003cvar translate=\"no\"\u003eVPC_NETWORK\u003c/var\u003e is the VPC network to attach your\n connector to.\n2. Create an ingress rule on your VPC network to allow requests\n from connectors:\n\n ```bash\n gcloud compute firewall-rules create vpc-connector-requests \\\n --allow tcp,udp,icmp \\\n --direction=INGRESS \\\n --source-tags vpc-connector \\\n --network=VPC_NETWORK\n ```\n\n This rule gives the VPC connector access to every resource in the network. To\n limit the resources that your serverless environment can reach using\n Serverless VPC Access,\n [specify a target for these firewall rules](/vpc/docs/firewalls#rule_assignment).\n\n### Create firewall rules for specific connectors\n\nFollowing the procedure in\n[Add firewall rules to allow IP ranges](#firewall-rules-shared-vpc)\nresults in firewall rules that apply to *all* connectors, both current ones\nand ones created in the future. If you don't want this, but instead want to\ncreate rules for specific connectors only, you can scope the rules so that\nthey apply only to those connectors.\n\nTo limit the scope of the rules to specific connectors, you can use one of the\nfollowing mechanisms:\n\n- Network tags. Every connector has two network tags: `vpc-connector` and `vpc-connector-`\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e`-`\u003cvar translate=\"no\"\u003eCONNECTOR_NAME\u003c/var\u003e. Use the latter format to limit the scope of your firewall rules to a specific connector.\n- IP ranges. Use this for the Egress rules only, because it doesn't work for Ingress. You can use the IP range of the connector subnet to limit the scope of your firewall rules to a single VPC connector.\n\nGrant permissions to service accounts in your service projects\n--------------------------------------------------------------\n\nFor each service project that will use VPC Connectors, a Shared VPC\nAdmin must grant the Compute Network User\nrole ([`compute.networkUser`](/compute/docs/access/iam#compute.networkUser)) in the\nhost project to the service project `cloudservices` and `vpcaccess` service\naccounts.\n\nTo grant the role:\n\n1. Use these commands:\n\n ```bash\n gcloud projects add-iam-policy-binding HOST_PROJECT_ID \\\n --role \"roles/compute.networkUser\" \\\n --member \"serviceAccount:service-\u003cvar translate=\"no\"\u003eSERVICE_PROJECT_NUMBER\u003c/var\u003e@gcp-sa-vpcaccess.iam.gserviceaccount.com\"\n ``` \n\n ```bash\n gcloud projects add-iam-policy-binding HOST_PROJECT_ID \\\n --role \"roles/compute.networkUser\" \\\n --member \"serviceAccount:\u003cvar translate=\"no\"\u003eSERVICE_PROJECT_NUMBER\u003c/var\u003e@cloudservices.gserviceaccount.com\"\n ```\n2. If the `@gcp-sa-vpcaccess` service account does not exist, turn on the\n Serverless VPC Access API in the service project and try again:\n\n ```bash\n gcloud services enable vpcaccess.googleapis.com\n ```\n\n \u003cbr /\u003e\n\nIf you prefer not to grant these service accounts access to the entire\nShared VPC network and would rather only grant access to specific subnets, you\ncan instead [grant these roles to these service accounts on specific subnets only](/vpc/docs/shared-vpc#svc_proj_admins).\n\nCreate a subnet\n---------------\n\nWhen using Shared VPC, the Shared VPC Admin must create a subnet\nfor each connector. Follow the documentation in\n[adding a subnet](/vpc/docs/create-modify-vpc-networks#add-subnets) to add a `/28` subnet to the\nShared VPC network. This subnet must be in the same region as the\nserverless services that will use the connector.\n\nNext steps\n----------\n\n- In the page [Configuring Serverless VPC Access](/vpc/docs/configure-serverless-vpc-access), complete the steps in the following sections:\n - [Create a Serverless VPC Access connector](/vpc/docs/configure-serverless-vpc-access#create-connector)\n - [Configure your serverless environment to use a connector](/vpc/docs/configure-serverless-vpc-access#configure-environment)"]]