简体   繁体   中英

Can't connect to VM from Google Cloud Function, but can connect from App Engine. Why is this?

Context:

  • VM Instance is essentially a Bastion host to tunnel into another.network for the sake of connecting to a non GCP hosted Database
  • All 3 resources (Function, Engine, and VM) live within the same GCP Project
  • App Engine uses the internal IP address of the VM
  • I've tried using the external and internal IP address for Google Cloud Function
  • Feeding the VM Instance's IP address(es) as the host option when configuring a mysql connection
  • Though on App Engine, i'm using the MySQL module within a node server
  • On the Cloud Function, i'm using the the Python sqlalchemy url creation module to create the connection
  • I've been getting a timeout error from the Google Cloud Function trying to connect, no matter how high I set the connection timeout -
  • I am able to get it to work from a local environment:
    • By:
      • SSHing into the VM
      • Setting host as localhost (and the relevant port)
    • So I've pinpointed it down to GCFunction failing to talk to the VM instance?

Cloud Functions requires Serverless VPC access to connect to a VPC private IP address.

A key item to understand is that Private (RFC1918) IP addresses are private. RFC1918 addresses do not route outside their.network. The same address can exist in multiple.networks and VPCs. You must set up a gateway/proxy/tunnel/connector to access a private IP address from another.network.

Google Cloud Functions Connecting to a VPC.network

Why is it that it works without a VPC for App Engine but a VPC is required for cloud functions

Which App Engine works (Standard or Flexible)?

App Engine Standard also requires Serverless VPC access to connect to a VPC private IP address. link

For App Engine Flexible, your app is actually deployed on a VM within the VPC. link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM