- Open the Google Cloud Console and select your project.
- Click on the “Navigation menu” (☰) and navigate to “Cloud Functions”.
- Click “Create Function” to create a new function.
- In the “Create Function” page, enter a name for your function and select a region.
- Choose “HTTP” as the trigger type and set the authentication to “Allow unauthenticated invocations” for simplicity.
- In the “Source code” section, select the “Inline editor” option and choose the desired runtime environment. For this example, we will use Node.js.
- Copy and paste the following code into the “index.js” file:
exports.helloWorld = (req, res) => {
let name = req.query.name || 'World';
res.send(`Hello, ${name}!`);
};
This code defines a simple HTTP function that returns a “Hello, World!” message, which can also be customized with a name
query parameter.
- In the “Function to execute” field, enter the name of the exported function (
helloWorld
in this case). - Click “Create” to create your function.
Once your function is deployed, you can test it by clicking the “Testing” tab and entering a value for the name
query parameter. You should see the message “Hello, <name>!” returned in the response.
Here’s an example of how to call the function using a simple HTTP GET request:
https://[REGION]-[PROJECT-ID].cloudfunctions.net/[FUNCTION-NAME]?name=John
Replace [REGION]
, [PROJECT-ID]
, and [FUNCTION-NAME]
with the appropriate values for your project and function.
That’s it! You’ve successfully created and deployed a simple Google Cloud Function using the Cloud Console. From here, you can explore more advanced features such as Cloud Pub/Sub triggers, Cloud Storage integrations, and more.