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): fix bedrock input/output path in step-funct… #31305

Merged
merged 19 commits into from
Sep 5, 2024

Conversation

shikha372
Copy link
Contributor

@shikha372 shikha372 commented Sep 3, 2024

Issue # (if applicable)

Closes #31302.

Reason for this change

PR#30298 introduced a breaking change in the stepfunctions-tasks which was encoding the input/output path from the TaskStateBaseProps to be used to input a S3 URI, which is not always the case and customer might be using the JSON string as it is.

Description of changes

To keep the functionality from the original ask of issue #29229 ,added another props to specify S3 URI as an input to the stepfunctions-tasks.

Introduced a feature flag to keep the existing behaviour for the customers and not introduce a breaking change.

Description of how you validated changes

Updated integ test and deployed in account

Integ Test Results:
aws stepfunctions start-execution --state-machine-arn <deployed state machine arn> : should return execution arn

A5-zEnXPmmPWTJx
{
"executionArn": "arn:aws:states:us-east-1:XXXX:execution:StateMachine2E01A3A5-zEnXPmmPWTJx:516f2e60-9507-46cb-95e6-4d9453429b08",
"startDate": "2024-09-04T15:43:33.200000-07:00"
}

aws stepfunctions describe-execution --execution-arn <exection-arn generated before> : should return status as SUCCEEDED

Checklist


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

@github-actions github-actions bot added bug This issue is a bug. p0 labels Sep 3, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team September 3, 2024 19:45
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Sep 3, 2024
Copy link
Member

@godwingrs22 godwingrs22 left a comment

Choose a reason for hiding this comment

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

Overall looks good. Just left few minor comments

@shikha372 shikha372 marked this pull request as ready for review September 3, 2024 20:28
@shikha372 shikha372 added the pr/do-not-merge This PR should not be merged at this time. label Sep 3, 2024
Comment on lines 237 to 238
InputPath: '$.prompt',
OutputPath: '$.prompt',
Copy link
Member

Choose a reason for hiding this comment

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

Are there other unit tests that test this functionality?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are two unit tests, one to check the expected template and one to check the permissions populated in policy

Copy link
Member

Choose a reason for hiding this comment

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

The title of this unit test is "invoke model allows input and output json path". I think this test was originally meant to test the original behavior of inputPath and outputPath. So we need an additional new test for these new s3InputUri and s3OutputUri params, AND fix this unit test to go back to testing the original behavior of inputPath and outputPath.

Copy link
Member

Choose a reason for hiding this comment

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

Update: I see in the history now that you had actually added this test in the last change. I do still think we should have both tests (inputPath and s3InputUri)

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 @clareliguori , this leads to one question can body be skipped in case of an inputPath ? since the earlier validation seems to added only for body and input and didn't point to a definition where we might be using these base props.

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see, yes you still need body. With inputPath, you would do something like body=sfn.JsonPath.object_at("$")

Copy link
Member

Choose a reason for hiding this comment

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

Yeah seems like I totally missed adding unit tests for inputPath and outputPath

Comment on lines 58 to 70
body: sfn.TaskInput.fromObject(
{
inputText: sfn.JsonPath.format(
'Alphabetize this list of first names:\n{}',
sfn.JsonPath.stringAt('$.names'),
),
textGenerationConfig: {
maxTokenCount: 100,
temperature: 1,
},
},
),
outputPath: sfn.JsonPath.stringAt('$.names'),
Copy link
Member

Choose a reason for hiding this comment

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

Can help me to understand why body is required instead of inputPath?

Copy link
Contributor Author

@shikha372 shikha372 Sep 3, 2024

Choose a reason for hiding this comment

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

just added this integ test is to make sure, we are not breaking any existing use case for outputPath or inputPath from the base class, looking back at why it might have been marked as required could be a decision taken while designing this s3 input parameter, i don't see it something as required in API doc

Copy link
Member

Choose a reason for hiding this comment

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

In order to test the inputPath field, you can do a Pass state to transform the previous output into the format expected for the InvokeModel body.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Sep 3, 2024
Comment on lines 73 to 79
/** Test for Bedrock s3 URI Path */
const prompt4 = new BedrockInvokeModel(stack, 'Prompt4', {
model,
s3InputUri: sfn.JsonPath.stringAt('$.names'),
s3OutputUri: sfn.JsonPath.stringAt('$.names'),
});

Copy link
Member

Choose a reason for hiding this comment

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

Can you run the verification steps listed at the top of this class?
Stack verification steps

@shikha372 shikha372 force-pushed the bedrock_input_path branch 13 times, most recently from df27bb4 to 9a4b791 Compare September 4, 2024 20:20
Comment on lines 14 to 16
postCliContext: {
'@aws-cdk/aws-cdk.aws-stepfunctions-tasks:useNewS3UriParametersForBedrockInvokeModelTask': true,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

if the default value of the flag is True, so we do not need to set this flag, and instead you need to update the old integration test cases to set the flag to false to test the current behaviour (using Input path, and output path instead of the new S3 uris)

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Sep 5, 2024
@shikha372
Copy link
Contributor Author

@Mergifyio update

Copy link
Contributor

mergify bot commented Sep 5, 2024

update

✅ Branch has been successfully updated

@shikha372 shikha372 removed the pr/do-not-merge This PR should not be merged at this time. label Sep 5, 2024
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 523c05d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

Copy link
Contributor

mergify bot commented Sep 5, 2024

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

@mergify mergify bot merged commit a190935 into main Sep 5, 2024
14 of 15 checks passed
@mergify mergify bot deleted the bedrock_input_path branch September 5, 2024 21:51
Copy link

github-actions bot commented Sep 5, 2024

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. contribution/core This is a PR that came from AWS. p0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

❗ NOTICE: stepfunctions-tasks: BedrockInvokeModel outputPath no longer passes output to next state
5 participants