Connect a VPC Network and Cloud Function

45 minutes
  • 3 Learning Objectives

About this Hands-on Lab

This hands-on lab demonstrates the techniques you’ll need to connect a Cloud Function to a GCP resource over an internal network using a Serverless VPC Access controller.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Enable APIs

Enable all the necessary APIs to create and connect a Cloud Function to an internal VPC network.

Set Up an Internal Wiki

Establish an open-source implementation of a wiki to be available only on the internal VPC.

Connect a New Cloud Function to a Serverless VPC Access Controller

Create a Cloud Function that would access the wiki via an internal VPC connection.

Additional Resources

In this scenario, your team leader has asked you to do the initial setup on a private, internal-only wiki that would be displayed when triggered by a yet-to-be-determined trigger. You decide to use an open-source wiki that would be triggered by a HTTP-driven Cloud Function.

Resources

Cloud Function code:

import functions_framework
import urllib

@functions_framework.http
def get_wikimedia(request):
    try:
        url = "http://[INTERNAL_IP]/wiki/Main_Page"
        req = urllib.request.Request(url)
        response = urllib.request.urlopen(req)
        return response.read()
    except Exception as e:
        print(e)
        return str(e)

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?