Skip to content

Commit

Permalink
update README to use RunLambdaTask in example
Browse files Browse the repository at this point in the history
  • Loading branch information
shivlaks committed Mar 23, 2020
1 parent 0b0c766 commit 3aab4d9
Showing 1 changed file with 12 additions and 29 deletions.
41 changes: 12 additions & 29 deletions packages/@aws-cdk/aws-stepfunctions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ const submitLambda = new lambda.Function(this, 'SubmitLambda', { ... });
const getStatusLambda = new lambda.Function(this, 'CheckLambda', { ... });

const submitJob = new sfn.Task(this, 'Submit Job', {
task: new tasks.InvokeFunction(submitLambda),
task: new tasks.RunLambdaTask(submitLambda, {
integrationPattern: sfn.ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN,
}),
// Put Lambda's result here in the execution's state object
resultPath: '$.guid',
});
Expand All @@ -45,7 +47,9 @@ const waitX = new sfn.Wait(this, 'Wait X Seconds', {
});

const getStatus = new sfn.Task(this, 'Get Job Status', {
task: new tasks.InvokeFunction(getStatusLambda),
task: new tasks.RunLambdaTask(getStatusLambda, {
integrationPattern: sfn.ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN,
}),
// Pass just the field named "guid" into the Lambda, put the
// Lambda's result in a field called "status"
inputPath: '$.guid',
Expand All @@ -58,7 +62,9 @@ const jobFailed = new sfn.Fail(this, 'Job Failed', {
});

const finalStatus = new sfn.Task(this, 'Get Final Job Status', {
task: new tasks.InvokeFunction(getStatusLambda),
task: new tasks.RunLambdaTask(getStatusLambda, {
integrationPattern: sfn.ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN,
}),
// Use "guid" field as input, output of the Lambda becomes the
// entire state machine output.
inputPath: '$.guid',
Expand Down Expand Up @@ -126,7 +132,6 @@ couple of the tasks available are:

* `tasks.InvokeActivity` -- start an Activity (Activities represent a work
queue that you poll on a compute fleet you manage yourself)
* `tasks.InvokeFunction` -- invoke a Lambda function with function ARN
* `tasks.RunBatchJob` -- run a Batch job
* `tasks.RunLambdaTask` -- call Lambda as integrated service with magic ARN
* `tasks.RunGlueJobTask` -- call Glue Job as integrated service
Expand All @@ -139,9 +144,9 @@ couple of the tasks available are:
* `tasks.StartExecution` -- call StartExecution to a state machine of Step Functions
* `tasks.EvaluateExpression` -- evaluate an expression referencing state paths

Except `tasks.InvokeActivity` and `tasks.InvokeFunction`, the [service integration
Except `tasks.InvokeActivity`, the [service integration
pattern](https://docs.aws.amazon.com/step-functions/latest/dg/connect-to-resource.html)
(`integrationPattern`) are supposed to be given as parameter when customers want
(`integrationPattern`) is supposed to be provided as a parameter when customers want
to call integrated services within a Task state. The default value is `FIRE_AND_FORGET`.

#### Task parameters from the state json
Expand All @@ -154,29 +159,7 @@ such as `Data.stringAt()`.
If so, the value is taken from the indicated location in the state JSON,
similar to (for example) `inputPath`.

#### Lambda example - InvokeFunction

```ts
const task = new sfn.Task(this, 'Invoke1', {
task: new tasks.InvokeFunction(myLambda),
inputPath: '$.input',
timeout: Duration.minutes(5),
});

// Add a retry policy
task.addRetry({
interval: Duration.seconds(5),
maxAttempts: 10
});

// Add an error handler
task.addCatch(errorHandlerState);

// Set the next state
task.next(nextState);
```

#### Lambda example - RunLambdaTask
#### Lambda example

```ts
const task = new sfn.Task(stack, 'Invoke2', {
Expand Down

0 comments on commit 3aab4d9

Please sign in to comment.