-
Notifications
You must be signed in to change notification settings - Fork 2
Schedule lambda function
You can orchestrate the executions of AWS Lambda functions in a workflow as shown in following example:
[WorkflowDescription("1.0", DefaultLambdaRole= "lambda role to invoke lambda function")]
public class BookHolidaysWorkflow : Workflow
{
public BookHolidaysWorkflow()
{
ScheduleLambda("BookHotel");
ScheduleLambda("AddDinner").After("BookHotel");
}
}
Create a role, as described in this article, and provide it either in WorkflowDescriptionAttribute or when starting the workflow. This role is needed by AWS SWF to invoke the lambda functions.
By default workflow's input is passed as input to the lambda function however you have can customize it. Following examples shows various ways to pass input to lambda function:
[WorkflowDescription("1.0")]
public class BookHolidaysWorkflow : Workflow
{
public BookHolidaysWorkflow()
{
ScheduleLambda("BookHotel").WithInput(_=> new {CustomerName = Input.CustomerName});
ScheduleLambda("AddDinner")
.WithInput(l=>new {BookingId = l.ParentLambda().Result().BookingId})
.After("BookHotel");
}
}
By default workflow is failed when lambda functions is failed/timedout however you can configure it take custom action as shown in below example:
[WorkflowDescription("1.0", DefaultLambdaRole= "lambda role to invoke lambda function")]
public class BookHolidaysWorkflow : Workflow
{
public BookHolidaysWorkflow()
{
//BookHotel lambda function will be rescheduled on failure. It will retry it for 2 times after which it will fail the workflow.
ScheduleLambda("BookHotel").OnFailure(e=>Reschedule(e).UpTo(times:2));
//AddDinner lambda will be rescheduled on timedout every time.
ScheduleLambda("AddDinner").After("BookHotel")
.OnTimedout(Reschedule);
}
}
ScheduleLambda API accept an optional argument "positionalName", which you can use to schedule same lambda function at multiple places in same workflow:
[WorkflowDescription("1.0", DefaultLambdaRole= "lambda role to invoke lambda function")]
public class BookHolidaysWorkflow : Workflow
{
public BookHolidaysWorkflow()
{
ScheduleLambda("TranscodeVideo", "WAVFormat").OnFailure(Reschedule);
ScheduleLambda("TranscodeVideo", "MP4Format").AfterLambda("TranscodeVideo", "WAVFormat")
.OnTimedout(Reschedule);
}
}
Guflow
- Prerequisite
- Installation
-
Workflows
- Creating first workflow
- Registration
- Hosting
- Start workflow
- Schedule activities
- Schedule timers
- Schedule lambda function
- Schedule child workflows
- Lambda functions vs activities
- Workflow input
- Workflow actions
- Signals
- Workflow branches
- Deflow algorithm
- Workflow events
- Query APIs
- Custom polling strategy
- Things to take care of
- Activites
- Unit testing
- Performance & scalability
- Error handling
- Logging
- Debugging
- Tutorial
- Release notes