Skip to content

Commit

Permalink
chore: add .NET example for step functions (#1019)
Browse files Browse the repository at this point in the history
Added a c# version for the first example.
  • Loading branch information
jonparker authored and rix0rrr committed Oct 26, 2018
1 parent 7f6f3fd commit 8c91766
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions packages/@aws-cdk/aws-stepfunctions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ serverless workflows. Using objects. Defining a workflow looks like this
(for the [Step Functions Job Poller
example](https://docs.aws.amazon.com/step-functions/latest/dg/job-status-poller-sample.html)):

### TypeScript example

```ts
const submitLambda = new lambda.Function(this, 'SubmitLambda', { ... });
const getStatusLambda = new lambda.Function(this, 'CheckLambda', { ... });
Expand Down Expand Up @@ -52,6 +54,66 @@ new stepfunctions.StateMachine(this, 'StateMachine', {
});
```

### .NET Example

```csharp
var submitLambda = new Function(this, "SubmitLambda", new FunctionProps
{
// ...
});

var getStatusLambda = new Function(this, "CheckLambda", new FunctionProps
{
// ...
});

var submitJob = new Task(this, "Submit Job", new TaskProps
{
Resource = submitLambda,
ResultPath = "$.guid"
});

var waitX = new Wait(this, "Wait X Seconds", new WaitProps
{
SecondsPath = "$.wait_time"
});

var getStatus = new Task(this, "Get Job Status", new TaskProps
{
Resource = getStatusLambda,
InputPath = "$.guid",
ResultPath = "$.status"
});

var jobFailed = new Fail(this, "Job Failed", new FailProps
{
Cause = "AWS Batch Job Failed",
Error = "DescribeJob returned FAILED"
});

var finalStatus = new Task(this, "Get Final Job Status", new TaskProps
{
Resource = getStatusLambda,
// Use "guid" field as input, output of the Lambda becomes the
// entire state machine output.
InputPath = "$.guid"
});

var definition = submitJob
.Next(waitX)
.Next(getStatus)
.Next(new Choice(this, "Job Complete?", new ChoiceProps())
.When(Amazon.CDK.AWS.StepFunctions.Condition.StringEquals("$.status", "FAILED"), jobFailed)
.When(Amazon.CDK.AWS.StepFunctions.Condition.StringEquals("$.status", "SUCCEEDED"), finalStatus)
.Otherwise(waitX));

new StateMachine(this, "StateMachine", new StateMachineProps
{
Definition = definition,
TimeoutSec = 300
});
```

## State Machine

A `stepfunctions.StateMachine` is a resource that takes a state machine
Expand Down

0 comments on commit 8c91766

Please sign in to comment.