Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs:(stepfunctions) Started adding dotnet examples #1019

Merged
merged 1 commit into from
Oct 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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