Skip to content

Google Cloud Function which is a HTTP-Trigger based function. Send message to Slack channel via webhook. PHP runtime.

Notifications You must be signed in to change notification settings

lemon57/cloud-function-http-trigger-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Cloud function triggered by http call

Google Cloud Function which is a HTTP-Trigger based function. It means that we can directly invoke it via a HTTPs endpoint that will be assigned to our function.

We are going to use this endpoint to send message to our test Slack channel test-webshop-cf

Runtime: PHP 7.4

Steps to run this function

  1. Open GCC by following this link Google cloud function list. You will see the list already existing functions.
  2. Check that you have installed Cloud SDK by running this command in terminal
gcloud

Check the list installed google cloud command tools

gcloud components list

If you are not authenticated in GCC then:

gcloud auth login
  1. Clone this repo
git clone [email protected]:lemon57/cloud-function-http-trigger-php.git
  1. Define Slack webhook url in config.php. You can find this webhook -> Slack channel webhook.
  2. Deploy this function:
gcloud functions deploy <FUNC_NAME> --trigger-http \
  --region=<REGION> --runtime=php74

Replace FUNC_NAME by your own function name.
Replace REGION by correct region name, in our case is europe-west1.

  1. Check that the function deployed successfully:
gcloud functions describe <FUNC_NAME> --region=<REGION>

or you can check the list of functions by this command:

gcloud functions list | grep <KEY_WORD_FROM_FUNC_NAME>
  1. Invoke the function by command:
gcloud functions call \
  --data '{"message":"Hello from boozt GCF workshop. Created by {your_name}"}' \
  <FUNC_NAME> --region=<REGION>
  1. Another way to trigger this function:
curl -H "Content-Type: application/json" \
 -X POST \
 -d '{"message":"Trigger GCF by curl command. By {your_name}"}' \
 https://<REGION>-<PROJECT_ID>.cloudfunctions.net/<FUNC_NAME>

Replace FUNC_NAME by name of our php function.
Replace REGION by current region in GCC project.
Replace PROJECT_ID by name of our project in GCC.
You can always check details about current project by this command:

gcloud config list

and then get more details about your project

gcloud projects describe <PROJECT_ID>
  1. Check the logs:
gcloud functions logs read --execution-id=<EXECUTION_ID> --region=<REGION_NAME>

Take EXECUTION_ID from the output after executing the command: gcloud functions call.

  1. Check slack channel test-webshop-cf

Play with other different parameters for gcloud command or chack the same functionality in GCC UI.

🚀 google ☁️

About

Google Cloud Function which is a HTTP-Trigger based function. Send message to Slack channel via webhook. PHP runtime.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages