Google Cloud Functions with VPC Serverless Connector Egress with Cloud NAT not working

Configure a sample Cloud NAT setup with Compute Engine. Use the Compute Engine to test if your settings for Cloud NAT were done successfully. Configuring Serverless VPC Access. Make sure you create the VPC connector on the custom-network1 made in step 1. Create a Google Cloud Function

Google Cloud Functions with VPC Serverless Connector Egress with Cloud NAT not working
  1. Configure a sample Cloud NAT setup with Compute Engine. Use the Compute Engine to test if your settings for Cloud NAT were done successfully.

  2. Configuring Serverless VPC Access. Make sure you create the VPC connector on the custom-network1 made in step 1.

  3. Create a Google Cloud Function

a.Under Networking choose the connector you created on step 2 and Route all traffic through the VPC connector.


import requests
import json

from flask import escape

def hello_http(request):

    response = requests.get('https://stackoverflow.com')

    print(response.headers)    
    return 'Accessing stackoverflow from cloud function:  {}!'.format(response.headers)

The Region for Cloud Nat, Vpc Connector and Cloud Function is us-central1