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

fix(stepfunctions-tasks): cannot specify part of execution data or task context as input to the RunLambda service integration #7428

Merged
merged 20 commits into from Apr 23, 2020

Conversation

shivlaks
Copy link
Contributor

@shivlaks shivlaks commented Apr 18, 2020

Commit Message

fix(stepfunctions-tasks): cannot specify part of execution data or task context as input to the RunLambda service integration (#7428)

The Lambda service integration requires an input field called payload.
We modeled this as a {[key: string]: any} which precludes the usage of
execution data or context data as inputs to a Lambda function.

Fix:
Change the type of payload to be TaskInput which has already modeled
a type union for task classes that accept multiple types of payload.
This will enable usage of literal strings, objects, execution data, and
task context as input types supported for invoking a Lambda function.

Rationale:
Although this is a breaking change, the workarounds for enabling usage of
different types is not user friendly and incomplete as all of the types
above cannot be expressed in the current modeling of payload

Fixes #7371

BREAKING CHANGE:
payload in RunLambdaTask is now of type TaskInput and has a default of the state input instead of the empty object.
You can migrate your current assignment to payload by supplying it to the TaskInput.fromObject() API

End Commit Message


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

…sk context as input to the service integration

The Lambda service integration requires an input field called `payload`.
We modeled this as a `{[key: string]: any}` which precludes the usage of
execution data or context data as inputs to a Lambda function.

Fix:
Change the type of `payload` to be `TaskInput` which has already modeled
a type union for task classes that accept multiple types of payload.
This will enable usage of literal strings, objects, execution data, and
task context.

Rationale:
Although this is a breaking change, the workarounds for enabling usage of
different types is not user friendly and incomplete as all of the types
above cannot be expressed in the current modeling of `payload`

Fixes #7371

BREAKING CHANGE:
`payload` in RunLambdaTask is now of type `TaskInput`.
You can migrate your current assignment to payload by supplying it to the `TaskInput.fromObject()` API
@shivlaks shivlaks added the @aws-cdk/aws-stepfunctions Related to AWS StepFunctions label Apr 18, 2020
@shivlaks shivlaks requested review from rix0rrr, nija-at and a team April 18, 2020 20:00
@mergify mergify bot added contribution/core This is a PR that came from AWS. labels Apr 18, 2020
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 714c023
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: a74353d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this change does not reflect in the README in any way, that means there is a missing example in there.

I would expect the first example of invoking a Lambda in the README to show how to pass the entire execution state to the Lambda (just like the old Lambda invocation used to do).

@@ -12,7 +12,7 @@ export interface RunLambdaTaskProps {
*
* @default - No payload
*/
readonly payload?: { [key: string]: any };
readonly payload?: sfn.TaskInput;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth introducing a new field for this? (Let's say, input?: sfn.TaskInput) and @deprecateing the old one?

Are you okay taking the breakage?


Next question: since we're touching this anyway, does it make sense to change the @default while we're at it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with the breaking change, given the migration is straight forward.

Why do you suggest changing the default? It seems to me that the current default makes sense, no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any problems with no payload being the default as long as there is a code example that shows how to set "Payload.$": "$" as @rix0rrr suggests.

$ (the entire input) could be a sensible default value, mostly out of convenience for users of the "old-style" InvokeFunction which always sent the effective input as the payload. I noted some caveats in #7371 (comment).

It may be worth adding test coverage for setting payload to $ since that's such a common use case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also okay with taking the breakage here for the same reason as @nija-at

good point: I do think the @default should be the entire task input while we're at it as I think that's a more common usage than sending the empty object into a Lambda. I've left it as is for now, but happy to make that change

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should optimize for the most common use case. What do we expect MOST people to do? @wong-a I would hope your team has some info on the most common ways people use each task type.

Furthermore, naively I would say that changing payload to $ by default is a non-breaking change. If people leave it empty, today they would get no parameters, so not expect them and not read them, so adding more parameters should be fine.

There's also the case of what the default outputPath should be. Feels like for maximum convenience it should be $.Payload, and similar for all other task types. But changing that is not backwards compatible so I guess that ship has sailed, huh...?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @wong-a, since we got you here anyway... what is the official term for the JSON blob that travels along with the execution, which is updated using inputPath, outputPath, etc?

I was struggling to find a good, clear and concise name for it while writing the library, so ultimately settled on something unsatisfying like Data. I wonder what you call it internally?

I guess we could do ExecutionState or something, but any term I can come up with feels so generic as to be worthless... :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we expect MOST people to do? @wong-a I would hope your team has some info on the most common ways people use each task type.

The old-style Lambda is the most used Task type, which uses the entire effective input and I think most customers would be happy with it as the default. If someone wants to pass an empty object as the payload they can easily do so by passing an empty object as the value of Payload.

what is the official term for the JSON blob that travels along with the execution, which is updated using inputPath, outputPath, etc?

There's no special name for it. It's generally referred to within the ASL spec and Step Functions documentation as "state input" or output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for that valuabe input @wong-a

I flipped this to default to $ as I agree with @rix0rrr that changing the payload from empty object to the state input is not likely to break the lambda being invoked as it wasn't expecting to read any input.

I will call it out in the breaking change entry.

@nija-at
Copy link
Contributor

nija-at commented Apr 20, 2020

If this change does not reflect in the README in any way, that means there is a missing example in there.

I would expect the first example of invoking a Lambda in the README to show how to pass the entire execution state to the Lambda (just like the old Lambda invocation used to do).

+1. I would further and say that a change to the README is useful given that this is a breaking change. We should have a couple of code snippets in the README of the common use cases.

@shivlaks
Copy link
Contributor Author

If this change does not reflect in the README in any way, that means there is a missing example in there.
I would expect the first example of invoking a Lambda in the README to show how to pass the entire execution state to the Lambda (just like the old Lambda invocation used to do).

+1. I would further and say that a change to the README is useful given that this is a breaking change. We should have a couple of code snippets in the README of the common use cases.

I've added some common cases. I'm in the middle of rewriting all of the Tasks section into stepfunctions-tasks package. It's taking be a bit longer than I thought, but I'd love to get all of this into the package (in another PR).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 1086bdb
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 7d91000
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 1a6cb7f
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 4cae476
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 05ec5d4
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@shivlaks
Copy link
Contributor Author

shivlaks commented Apr 21, 2020

@nija-at @rix0rrr - I started drafting the updated README for stepfunctions-tasks in #7469
Going to be adding in all the service integrations before that one will be ready for review. Happy to port over wherever we land on this one.

One thing I've noticed is inconsistency in how we name these task integrations.

Some services have Run as a prefix -> i.e. RunBatchJob
Some services have Task at the suffix as well RunLambdaTask, RunGlueJobTask
Some services have <service-name><api-name> - i.e. EmrAddStep, CallDynamoDb.putItem(...)
Some services are excluded altogether - i.e. PublishToTopic, SendToQueue

I guess it would be nice if the naming wasn't so heterogeneous. Do we want to align the naming? If we do, an alternative could be to rename RunLambdaTask to whatever we settle on. I personally like the

@nija-at
Copy link
Contributor

nija-at commented Apr 21, 2020

Do we want to align the naming?

Would be nice to align. If I was starting off, I would do <ServiceName><ApiName>Task; service name first is easier to discover.

We should be ok changing the names of more recent ones that were added (batch, dynamo, emr, etc.). We'll break fewer customers. I'm sure most people using stepfunctions will use lambda.

packages/@aws-cdk/aws-stepfunctions/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-stepfunctions/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-stepfunctions/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-stepfunctions/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-stepfunctions/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-stepfunctions/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-stepfunctions/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-stepfunctions/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-stepfunctions/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-stepfunctions/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-stepfunctions/README.md Outdated Show resolved Hide resolved
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: edd4122
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: f053868
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: e3fc24f
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@shivlaks shivlaks requested a review from rix0rrr April 22, 2020 08:08
@shivlaks
Copy link
Contributor Author

Do we want to align the naming?

Would be nice to align. If I was starting off, I would do <ServiceName><ApiName>Task; service name first is easier to discover.

We should be ok changing the names of more recent ones that were added (batch, dynamo, emr, etc.). We'll break fewer customers. I'm sure most people using stepfunctions will use lambda.

I agree, I'll take a stab at a first approximation in another PR

@nija-at nija-at added the pr/do-not-merge This PR should not be merged at this time. label Apr 22, 2020
Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the updates to the README.

Provisional approval. Some comments below.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 841074d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 3f6429f
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 91892e8
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 1029f30
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: a99b6c5
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@shivlaks shivlaks removed the pr/do-not-merge This PR should not be merged at this time. label Apr 23, 2020
@mergify
Copy link
Contributor

mergify bot commented Apr 23, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: bc2e83d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: f930df8
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Apr 23, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

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 contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

StepFunctions - RunLambdaTask with Payload not working
5 participants