Source: Google Cloud Blog |
We recently announced that the recently released .NET 5.0 is coming to the Google Cloud. Among the many benefits of using .NET in Google Cloud is the ability to build and run .NET apps on a serverless platform like Google Cloud Functions. Since another feature in preview is the ability to run .NET apps on Cloud Functions, let's understand how all of that works.
What is Cloud Functions?
Cloud Functions is Google Cloud’s Function-as-a-Service platform that allows developers to build serverless apps. Since serverless apps do not require a server to run, cloud functions are a great fit for serverless applications, mobile or IoT backends, real-time data processing systems, video, image and sentiment analysis and even things like chatbots, or virtual assistants.
FaaS
To develop your .NET apps so they're compatible with Cloud Functions, Google has made available this GitHub repo. The Functions Framework lets you write lightweight functions that run in many different environments, including:
- Google Cloud Functions
- Your local development machine
- Cloud Run and Cloud Run on GKE
- Knative-based environments
Building your C# App
Assuming you're using .NET Core, the first thing you'll need is to build and run a deployable container on your local machine. For that, make sure that you have either Docker and the pack tool installed.
Next, build a container from your function using the Functions buildpacks:
--builder gcr.io/buildpacks/builder:v1 \
--env GOOGLE_FUNCTION_SIGNATURE_TYPE=http \
--env GOOGLE_FUNCTION_TARGET=HelloFunctions.Function \ my-first-function
Start the built container:
# Output: Serving function...
Send a request to this function by navigating to localhost:8080. You should
see
Hello, Functions Framework.
Cloud Event Functions
After installing the same template package described above, use the gcf-event
template:
mkdir HelloEvents cd HelloEvents dotnet new gcf-event
VB and F# support
The templates package also supports VB and F# projects. Just use -lang vb or -lang f# in the dotnet new command. For example, the HTTP function example above can be used with VB like this:mkdir HelloFunctions
dotnet new gcf-http -lang vb
Running your function on serverless platforms
After you finished your project. you can use the Google Cloud SDK to deploy to Google Cloud Functions from the command line with the gcloud tool.
Once you have created and configured a Google Cloud project (as described in the Google Cloud Functions Quickstarts and installed the Google Cloud SDK, open a command line and navigate to the function directory. Use the gcloud functions deploy command to deploy the function.
For the quickstart HTTP function described above, you could run:
Note that other function types require different command line options. See the deployment documentation for more details.
Trying Cloud Functions for .NET
To get started with Cloud Functions for .NET, read the quickstart guide and learn how to write your first functions. You can even try it out with a Google Cloud Platform free trial.
References
- .NET FaaS Reference - GitHub
- Introducing .NET on Google Cloud Functions
- A tour of the .NET Functions Framework
See Also
-
Get Started with the new Cloud Shell Editor
- HTTP/gRPC server streaming available in Google Cloud Run
- .NET, Java and Ruby now available in Google Cloud Functions
- Eventrac, a new events functionality to build event-driven applications on the Google Cloud
- Docker and Apache Flink available in Dataproc’s Component Exchange
- Logs Buckets and Log Views now available in the Google Cloud Platform