Introduction
This project focuses on deploying an HTTP-triggered Cloud Function on Google Cloud. Cloud Functions is a serverless execution environment where you can run code without provisioning or managing servers.
Why Is It Useful?
Prerequisites
Before you begin, ensure you have:
A Google Cloud Account (Free Tier, No Credits Required)Sign up at cloud.google.com. Choose a region that supports the Cloud Functions free usage.
Google Cloud SDK Installed (gcloud CLI)Download and install from Google Cloud SDK Install.
Proper Permissions You need Owner or Editor IAM role on your project to create and deploy Cloud Functions.
Cloud Functions API Enabled Confirm Cloud Functions API is active in your project. You can do this via the APIs & Services page or the CLI command below.
Step 1: Select or Create a Project
Step 2: Enable Cloud Functions API
Step 3: Create a Simple Function (Code + Deployment)
We’ll use a minimal example function in Node.js (although you can choose other runtimes).
A. Write/Review Your Function Code
Let’s call our function HelloHTTP. It returns a simple JSON response:
/**
* HTTP Cloud Function.
*
* @param {Object} req Cloud Function request context.
* @param {Object} res Cloud Function response context.
*/
exports.helloHttp = (req, res) => {
res.status(200).send({ message: "Hello from Cloud Functions!" });
};
Save this as index.js. If your runtime is Node.js 18, also create a package.json if needed:
{
"name": "hello-http-function",
"version": "1.0.0",
"main": "index.js"
}
Deploy the Cloud Function
Console : Go to Cloud Functions (under “Serverless” or search “Cloud Functions” in the top search bar). Click Create Function. Function Name: helloHttp Region: Choose a region that qualifies for free tier usage (e.g., us-central1). Trigger type: Select HTTP. Runtime: Select Node.js 18 (or whichever you prefer). Entry point: helloHttp (match the exported function name). In the Source code section, you can choose “Inline editor” and paste the code from above (index.js and optional package.json) or “ZIP upload/Cloud Source Repositories.” Check Allow unauthenticated invocations if you want it publicly accessible. Click Deploy.
CLI : Inside a folder containing index.js (and package.json if used), run: gcloud functions deploy helloHttp \ --region=us-central1 \ --runtime=nodejs18 \ --trigger-http \ --allow-unauthenticated \ --entry-point=helloHttp
5. Verifying and Testing the Project
Check Deployment Status
Invoke the Function
Logs & Monitoring
Conclusion
In this project, we have:
Created a Cloud Function on Google Cloud that responds to HTTP requests.
Learned Console steps (GUI) and CLI commands (gcloud) side by side.
Verified that the function is live and responding without incurring extra costs.
Popular Projects
What is Cloud Computing ?
Cloud computing delivers computing resources (servers, storage, databases, networking, and software) over the internet, allowing businesses to scale and pay only for what they use, eliminating the need for physical infrastructure.