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

aws-stepfunctions-tasks: Confusion between RunLambdaTask and InvokeFunction #4801

Closed
otterley opened this issue Oct 31, 2019 · 9 comments · Fixed by #6796
Closed

aws-stepfunctions-tasks: Confusion between RunLambdaTask and InvokeFunction #4801

otterley opened this issue Oct 31, 2019 · 9 comments · Fixed by #6796
Assignees
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions effort/medium Medium work item – several days of effort feature-request A feature should be added or improved.

Comments

@otterley
Copy link
Contributor

There are now two similar-looking constructs in aws-stepfunctions-tasks pertaining to Lambda tasks, and it's not clear which one to use.

Users who are used to historical Step Functions patterns and want things to easily work should use InvokeFunction. However, there are some corner cases where people want special behavior (e.g., asynchronous execution) who like to use RunLambdaTask.

If you mix these up, be prepared to spend a lot of time debugging. @ccfife and I spent the afternoon scratching our heads to figure out, when we accidentally used RunLambdaTask, why the event payload being sent to our Lambda function Tasks was an empty event.

Let's do something to disambiguate these and make clear when a user should use one or the other.

@otterley otterley added the needs-triage This issue or PR still needs to be triaged. label Oct 31, 2019
@SomayaB SomayaB added the @aws-cdk/aws-stepfunctions Related to AWS StepFunctions label Nov 1, 2019
@SomayaB SomayaB added feature-request A feature should be added or improved. and removed needs-triage This issue or PR still needs to be triaged. labels Nov 11, 2019
@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 13, 2019

I'm open to ideas for good verbiage to put in the class descriptions.

@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 13, 2019

Or the README

@rix0rrr rix0rrr added docs/generated Related to the generated API Reference documentation good first issue Related to contributions. See CONTRIBUTING.md labels Dec 2, 2019
@rix0rrr rix0rrr assigned nija-at and unassigned rix0rrr Jan 23, 2020
@nija-at nija-at added effort/medium Medium work item – several days of effort and removed docs/generated Related to the generated API Reference documentation good first issue Related to contributions. See CONTRIBUTING.md labels Feb 28, 2020
shivlaks added a commit that referenced this issue Mar 27, 2020
…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
@sacag
Copy link

sacag commented Apr 14, 2020

Since I am getting obsolete warning on InvokeFunction(this has been working fine for us), we moved to RunLambdaTask. Since then we have been receiving null ref exception in the lambda function. Seems like the payload passed to lambda function is null? Any thoughts? @rix0rrr @otterley The code with InvokeFunction looked like this:
I am using C#

            var postToApiTask = new Task(scope, $"{props.UniqueFunctionSuffix}-PostAPI-Task", new TaskProps
            {
                Task = new InvokeFunction(props.PostToAPILambda), //this is the lambda function
                InputPath = "$",
                ResultPath = "$.data.lambdaResult",
                Comment = "This task invokes API endpoint",
                Timeout = Duration.Seconds(30)
            });

I just replace InvokeFunction with RunLambdaTask. I tried setting some properties as well, but no luck.

@shivlaks
Copy link
Contributor

@sacag can you share the code that you were using when you converted to RunLambdaTask? which properties did you set?

Did you set the IntegrationPattern property? Wondering if it's the default of FIRE_AND_FORGET that's biting you here.

In TypeScript it would look something like this:

  task: new tasks.RunLambdaTask(postToAPILambda, {
    integrationPattern: sfn.ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN,
    payload: {
      token: sfn.Context.taskToken
    }
  }),
  inputPath: '$',
  resultPath: '$.lambdaResult',
  comment: 'This task invokes API endpoint',
  timeout: Duration.seconds(30)
});

@sacag
Copy link

sacag commented Apr 14, 2020

@shivlaks - I did not set the IntegrationPattern property. Also, my lambda function is not accepting/returning any token or anything of that sort. Below is how my C# code looks like:
var postToApiTask = new Task(scope, $"{props.UniqueFunctionSuffix}-PostAPI-Task", new TaskProps { Task = new InvokeFunction(postToAPILambda), //this is the lambda function InputPath = "$", ResultPath = "$.data.lambdaResult", Comment = "This task invokes API endpoint", Timeout = Duration.Seconds(30) });

In the above code I just replaced InvokeFunction with RunLambdaTask and it stopped working

Are you suggesting I shall try with the props you are setting in your typescript code and see? without any changes to the lambda function?

@sacag
Copy link

sacag commented Apr 14, 2020

@shivlaks - I tried Context.EntireContext, Context.TaskToken..still same issue

            var applyFilterTransformTask = new Task(scope, $"{props.UniqueFunctionSuffix}-FilterTransform-Task", new TaskProps
            {
                Task = new RunLambdaTask(props.FilterTransformLambda, 
                        new RunLambdaTaskProps { IntegrationPattern = ServiceIntegrationPattern.WAIT_FOR_TASK_TOKEN, 
                                                Payload = new Dictionary<string, object>() { { "input",Context.EntireContext} } }),
                Comment = $"This task applies source/destination filters to {props.UserFriendlyTopicName} Message and also Transforms it",
                InputPath = "$",
                ResultPath = "$.data.lambdaResult",
                OutputPath = "$.data.lambdaResult",
                Timeout = Duration.Seconds(15),                
            });

@sacag
Copy link

sacag commented Apr 14, 2020

image
@shivlaks

@sacag
Copy link

sacag commented Apr 14, 2020

@shivlaks - finally got it to work with the below code:
new RunLambdaTask(props.PostToAPILambda,new RunLambdaTaskProps { Payload = new Dictionary<string, object>() { { "input", Context.StringAt("$$.Execution.Input") } } })

@sacag
Copy link

sacag commented Apr 15, 2020

@shivlaks, @rix0rrr - I am seeing more issues with RunLambdaTask:
below is the code which works with InvokeFunction..$.Payload has my model in json string

 Task = new InvokeFunction(lambdaFunction),                
                InputPath = "$.Payload",
                ResultPath = "$.lambdaResult",
                OutputPath = "$.lambdaResult"

The same code when using RunLambdaTask...not sure how to access $.Payload in the Payload property, so that it can be passed over to the Lambda function? This is what I have. This passes NULL to my lambda function

Task = new RunLambdaTask(lambdaFunction,
                            new RunLambdaTaskProps 
{ Payload = new Dictionary<string, object>() { { "lambdaResult", Context.StringAt("$$.Payload") } } }),
                InputPath = "$.Payload",
                ResultPath = "$.lambdaResult",
                OutputPath = "$.lambdaResult"

When I do Context.StringAt(...) in RunLambdaTask, i think it takes the execution's input and not the task input..i think, maybe there is another way to access the TaskState input?
@otterley - wondering if you were able to figure this out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions effort/medium Medium work item – several days of effort feature-request A feature should be added or improved.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants