通过无服务器VPC连接器向GCE发出GAE http请求



我有一个Google App Engine应用程序(python 2.7-这是一个正在升级的旧项目!(,需要对Google计算引擎上的Elastisearch实例进行查询。我可以使用GCE公共ip地址进行请求,但我不希望将GCE实例暴露在公共互联网上。

  • 应用程序引擎应用程序位于美国中部地区
  • 计算引擎实例位于区域us-central1-f中
  • 计算引擎实例在vpc网络"中;默认";。(不是传统网络(
  • 我在us-central1中,在默认网络上设置了一个无服务器VPC连接器
  • 我已经将应用程序引擎app.yaml设置为使用连接器

但是对计算引擎专用IP地址(10.128.0.2(的http请求连接失败,和对计算引擎的内部DNS名称的DNS查找失败编辑:使用socket.gethostbyname进行DNS查找确实有效。

error: An error occured while connecting to the server: Unable to connect to server at URL: http://10.128.0.2:9200/indexname

当使用公共IP地址时(当我打开9200端口上的VPC防火墙时(,同样的请求成功。

应用程序引擎应用程序配置中的代码段:

runtime: python27
api_version: '1'
env: standard
threadsafe: false
instance_class: F4
network:
name: default
vpc_access_connector:
name: >-
projects/myproject/locations/us-central1/connectors/connector0301

gcloud beta-帐户=";myaccount"--项目=";myproject";应用程序描述:

authDomain: gmail.com
codeBucket: staging.myproject.appspot.com
databaseType: CLOUD_DATASTORE_COMPATIBILITY
defaultBucket: myproject.appspot.com
defaultHostname: myproject.appspot.com
featureSettings:
splitHealthChecks: true
useContainerOptimizedOs: true
gcrDomain: us.gcr.io
id: myproject
locationId: us-central
name: apps/myproject
servingStatus: SERVING

gcloud beta-帐户=";myaccount"--项目=";myproject";计算实例描述(仅网络片段(:

networkInterfaces:
- accessConfigs:
- kind: compute#accessConfig
name: External NAT
natIP: SNIPPED
networkTier: PREMIUM
type: ONE_TO_ONE_NAT
fingerprint: M087cXbOWII=
kind: compute#networkInterface
name: nic0
network: https://www.googleapis.com/compute/beta/projects/myproject/global/networks/default
networkIP: 10.128.0.2
subnetwork: https://www.googleapis.com/compute/beta/projects/myproject/regions/us-central1/subnetworks/default

gcloud beta-帐户=";myaccount"--项目=";myproject";计算网络vpc访问

connectors list --region=us-central1
CONNECTOR_ID   REGION       NETWORK  IP_CIDR_RANGE  MIN_THROUGHPUT  MAX_THROUGHPUT  STATE
connector0301  us-central1  default  10.8.0.0/28    200             300             READY

gcloud beta-帐户=";myaccount"--项目=";myproject";计算网络vpc访问连接器描述连接器0301-region=us-central1

ipCidrRange: 10.8.0.0/28
maxThroughput: 300
minThroughput: 200
name: projects/myproject/locations/us-central1/connectors/connector0301
network: default
state: READY

gcloud--帐户=";myaccount"--项目=";myproject";计算防火墙规则描述默认允许内部

allowed:
- IPProtocol: tcp
ports:
- 0-65535
- IPProtocol: udp
ports:
- 0-65535
- IPProtocol: icmp
creationTimestamp: '2020-02-11T11:18:09.906-08:00'
description: Allow internal traffic on the default network
direction: INGRESS
disabled: false
id: '1434668200291681054'
kind: compute#firewall
logConfig:
enable: true
name: default-allow-internal
network: https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default
priority: 65534
selfLink: https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls/default-allow-internal
sourceRanges:
- 10.128.0.0/9
- 10.8.0.0/28

无服务器VPC连接器不适用于内部IP http请求吗?

无服务器VPC连接器不适用于内部IP http请求吗?

无服务器VPC连接器在python37运行时使用urllib.request处理内部IP http请求,但在python27运行时不使用google.appengine.api中的urllib2urlfetch。(提醒urlib2在应用程序引擎python27的引擎盖下使用urlpetch(

由于这是一个从python27慢慢过渡到python37的旧项目的一部分,因此目前我将内部iphttp请求放入一个单独的服务中,以便它们可以使用新的运行时。

最新更新