Skip to content

Commit

Permalink
fix(stepfunctions-tasks): confusion between multiple ways to run a La…
Browse files Browse the repository at this point in the history
…mbda (#6796)

The InvokeFunction Step Functions task is being marked as deprecated. It represents the legacy way to represent Lambda functions in Step Functions

The RunLambda task represents the recommended way to invoke Lambdas in Step Functions.
see: https://docs.aws.amazon.com/step-functions/latest/dg/connect-lambda.html

Examples in the README have been updated to use RunLambdaTask

Closes #4801
  • Loading branch information
shivlaks authored Mar 27, 2020
1 parent e52097a commit 7485448
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import * as sfn from '@aws-cdk/aws-stepfunctions';

/**
* Properties for InvokeFunction
*
* @deprecated use `RunLambdaTask`
*/
export interface InvokeFunctionProps {
/**
Expand All @@ -22,6 +24,8 @@ export interface InvokeFunctionProps {
* The Lambda function Arn is defined as Resource in the state machine definition.
*
* OUTPUT: the output of this task is the return value of the Lambda Function.
*
* @deprecated Use `RunLambdaTask`
*/
export class InvokeFunction implements sfn.IStepFunctionsTask {
constructor(private readonly lambdaFunction: lambda.IFunction, private readonly props: InvokeFunctionProps = {}) {
Expand Down
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 @@ -127,7 +133,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 @@ -140,9 +145,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 @@ -155,29 +160,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 7485448

Please sign in to comment.