Connecting Cloud Run functions with workflows
1. Connecting Cloud Run functions with workflows
Let’s now discuss how you can use Workflows to connect Cloud Run functions and link a series of services together. What is Workflows? Workflows is a fully-managed, serverless orchestration platform that executes services in an order that you define (a workflow). It acts as the central orchestrator for the service orchestration pattern. You design and deploy workflows, which orchestrate and combine Google Cloud services and API calls. To build stateful, automated processes, Workflows can include custom services or functions that are hosted on Cloud Run. A workflow provides a central source-of-truth for the application flow. Each execution of a workflow is logged and is observable, which makes it easier to understand the current state of the workflow and troubleshoot any issues. A workflow can hold state, retry, poll, or wait for up to a year. This flexibility allows for creation of long-running business processes. You can use Workflows to connect a series of services together that include HTTP services built with Cloud Run functions, external APIs, and other Cloud services like Cloud Run. With this approach, you can create a flexible serverless application. The first step to build a workflow is to enable the required Google APIs for Cloud Run functions, Cloud Run, Workflows, and any other services that you use. You may also need to create any service accounts that are required to access these services. Next, write, and deploy the functions. These functions are HTTP functions with HTTP triggers that generate URL endpoints that are used to invoke the functions. Test the functions individually with curl or any other HTTP client. It’s also a best practice to test the functions locally before deployment. You then create the workflow that connects the Cloud Run functions. After the workflow is created, you deploy and execute it. A workflow is made up of a series of steps that are described using the Workflows syntax. The set of steps is the workflow definition and can be written in either YAML or JSON format. In the sample workflow definition, the Cloud Run functions steps cfn1 and cfn2, are invoked from the workflow through an HTTP request using the GET and POST methods respectively. The URLs to the functions are provided as arguments in the function definition. The result generated by the first cloud function is provided as input to the second cloud function. The workflow definition also includes: The configuration to connect to an external REST API endpoint with the result of the second cloud function passed in a query parameter. And, configuration that connects a Cloud Run service in the workflow. The result generated by the Cloud Run service is the result of the workflow. In this section, we discuss how you can connect Cloud Run functions to resources in a VPC network. You use Serverless VPC Access to connect Cloud Run functions directly to your VPC network. A Virtual Private Cloud (VPC) network is a virtual version of a physical network, implemented inside Google's production network. It’s a global resource that consists of a list of regional virtual subnetworks (subnets) in data centers, all connected by a global wide area network. With Serverless VPC Access, you can connect Cloud Run functions directly to your VPC network, and enable access to Compute Engine VM instances, Memorystore, and other resources with an internal IP address. With Serverless VPC Access, you can send requests and receive responses to and from your VPC network using internal DNS and internal IP addresses, so that traffic is not exposed to the internet. To configure Serverless VPC Access, you: Enable the Serverless VPC Access API. Create a Serverless VPC Access connector in your Google Cloud project. A Serverless VPC Access connector is a resource that handles traffic between your serverless Cloud Run functions environment and your VPC network. Attach the connector to a VPC network and region. The region that is configured for the connector must match the region where your Cloud Run functions are deployed. A subnet or CIDR range must be configured exclusively for use by the connector. After you have created a Serverless VPC Access connector, you must configure each function that you want to connect to your VPC network. You can configure a function to use a connector from the Google Cloud console or the gcloud CLI. You can also restrict your connector's access to resources in your VPC network by using firewall rules, and connect Cloud Run functions to resources in a shared VPC network. For more information on configuring Serverless VPC Access connectors, refer to the reading document provided with this course, and the Cloud Run functions website documentation.2. Let's practice!
Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.