11

I currently have a Prefect workflow running locally on an EC2 instance. I can trigger my workflow on localhost:8080 through the UI. Is there a way to trigger a Prefect workflow externally (say AWS Lambda) via REST API or some other way?

I know that Airflow supports an experimental REST API.

LifeAndHope
  • 674
  • 2
  • 10
  • 27

2 Answers2

11

Yes, Prefect exposes a full GraphQL API that you can use to perform all types of actions, including the scheduling / triggering of a workflow. This blog post goes into more detail, and here is some code for setting up an AWS Lambda function to trigger Prefect flow runs.

chriswhite
  • 1,370
  • 10
  • 21
  • In theory, yes, but note that this requires an accessible API endpoint - one of the benefits of Cloud is that this endpoint is by default available to all services as long as you provide an authentication token. – chriswhite Mar 29 '21 at 21:08
  • Ah, I see. I kept looking for something similar to Airflow REST API where you can trigger a DAG run. But if I understood you right, for Prefect you'd need to incorporate Prefect library into your own service (Django, etc), right? – Turar Mar 30 '21 at 01:38
  • Prefect exposes a GraphQL API (also available in Prefect Server) but the Lambda function needs API access to the endpoint which can be a tricky networking problem, depending on your setup. – chriswhite Mar 30 '21 at 17:06
  • hey @chriswhite I am new to prefect and have setup prefect locally, is it possible to trigger my workflow externally using API or anything else ? or workflow can be externally triggered only when prefect is on cloud ? – NeedToCodeAgain Jan 09 '23 at 16:20
  • Hi @NeedToCodeAgain - yea you can, you'll need to make the API accessible by whatever external service needs to make the POST request – chriswhite Jan 31 '23 at 22:13
3

Yes through REST API you can trigger it using AWS Lambda, and can schedule AWS Lambda trigger using CloudWatch Events Rule, it supports both fixed rate or crown expression scheduler

Asfar Irshad
  • 658
  • 1
  • 4
  • 20