The easiest way is to create a pub/sub topic, cron-topic
that your cloud function subscribes to. Cloud Scheduler can push an event to cron-topic
on a schedule
Create the Topic & Subscription
gcloud pubsub topics create cron-topic
# create cron-sub for testing. Function will create it's own subscription
gcloud pubsub subscriptions create cron-sub --topic cron-topic
Create the Schedule
Command is below, but since it's beta, see the console guide here
# send a message every 3 hours. For testing use `0/2 * * * *` for every 2 min
gcloud beta scheduler jobs create pubsub --topic=cron-topic --schedule='0 */3 * * *'
Create a Function to Consume the cron-topic
Topic
Put your function code in the current directory and use this command to deploy the function listening to the cron-topic
topic
FUNCTION_NAME=cron-topic-listener
gcloud functions deploy ${FUNCTION_NAME} --runtime go111 --trigger-topic cron-topic
note pub/sub events are sent at least once. In some cases the event can be sent more than once. Make sure your function is idempotent