cr_run_schedule_http: Create a Cloud Scheduler HTTP target for a private Cloud Run...

View source: R/cloudrun_schedule.R

cr_run_schedule_httpR Documentation

Create a Cloud Scheduler HTTP target for a private Cloud Run URI

Description

This enables Cloud Scheduler to trigger Cloud Run endpoints when they are not public.

Usage

cr_run_schedule_http(uri, email, http_method = "GET", body = NULL)

Arguments

uri

The URI of your Cloud Run application

email

The service email that has invoke access to the Cloud Run application. If using cr_run and derivatives to make the email this will include (name)-cloudrun-invoker@(project-id).iam.gserviceaccount.com - see cr_run_email to help make the email.

http_method

The HTTP verb you have set up your Cloud Run application to receive

body

(optional) An R list object that will be turned into JSON via toJSON and turned into a base64-encoded string if you are doing a POST, PUT or PATCH request.

Details

Ensure you have a service email with cr_email_set of format service-{project-number}@gcp-sa-cloudscheduler.iam.gserviceaccount.com with Cloud Scheduler Service Agent role as per https://cloud.google.com/scheduler/docs/http-target-auth#add

Value

A HttpTarget object for use in cr_schedule

See Also

https://cloud.google.com/run/docs/triggering/using-scheduler

cr_schedule_http and cr_run and cr_deploy_run

Other Cloud Scheduler functions: HttpTarget(), Job(), PubsubTarget(), cr_build_schedule_http(), cr_schedule_delete(), cr_schedule_get(), cr_schedule_list(), cr_schedule_pause(), cr_schedule_run()

Other Cloud Run functions: cr_jwt_create(), cr_plumber_pubsub(), cr_run_email(), cr_run_get(), cr_run_list(), cr_run()

Examples

## Not run: 
# for unauthenticated apps create a HttpTarget
run_me <- HttpTarget(
  uri = "https://public-ewjogewawq-ew.a.run.app/echo?msg=blah",
  http_method = "GET"
)
cr_schedule("cloud-run-scheduled",
  schedule = "16 4 * * *",
  httpTarget = run_me
)

# for authenticated Cloud Run apps - create with allowUnauthenticated=FALSE
cr_deploy_run("my-app", allowUnauthenticated = TRUE)

## End(Not run)

# deploying via R will help create a service email called my-app-cloudrun-invoker
cr_run_email("my-app")
## Not run: 
# use that email to schedule the Cloud Run private micro-service

# schedule the endpoint
my_run_name <- "my-app"
my_app <- cr_run_get(my_run_name)
email <- cr_run_email(my_run_name)
endpoint <- paste0(my_app$status$url, "/fetch_stuff")

app_sched <- cr_run_schedule_http(endpoint,
  http_method = "GET",
  email = email
)

cr_schedule("cloud-run-scheduled-1",
  schedule = "4 16 * * *",
  httpTarget = app_sched
)

## End(Not run)


googleCloudRunner documentation built on March 18, 2022, 8 p.m.