aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

(stepfunctions-tasks): BedrockInvokeModel cannot use JsonPath to specify input/output S3 URIs

Open SamStephens opened this issue 1 year ago • 1 comments

Describe the bug

If you try and use JsonPath to specify the S3 URIs that BedrockInvokeModel will read from and write from, you get an error.

Expected Behavior

I expect to be able to provide S3 URIs to BedrockInvokeModel using JsonPath, so I can have dynamic paths for different state machine executions.

Current Behavior

I get the error

jsii.errors.JavaScriptError:
  Error: Field references must be the entire string, cannot concatenate them (found 's3://${Token[prompt_bucket.348]}/${Token[prompt_key.349]}')

Reproduction Steps

tasks.BedrockInvokeModel(
    scope=self,
    id="Call LLM",
    model=aws_bedrock.FoundationModel.from_foundation_model_id(
        scope=self,
        _id="Model",
        foundation_model_id=aws_bedrock.FoundationModelIdentifier.ANTHROPIC_CLAUDE_V2_1,
    ),
    input=tasks.BedrockInvokeModelInputProps(
        s3_location=aws_s3.Location(
            bucket_name=aws_stepfunctions.JsonPath.string_at("$.prompt_bucket"),
            object_key=aws_stepfunctions.JsonPath.string_at("$.prompt_key"),
        ),
    ),
    output=tasks.BedrockInvokeModelOutputProps(
        s3_location=aws_s3.Location(
            bucket_name=aws_stepfunctions.JsonPath.string_at("$.response_bucket"),
            object_key=aws_stepfunctions.JsonPath.string_at("$.response_key"),
        ),
    ),
)

Possible Solution

The issue here is that the S3 locations are specified as an aws_s3.Location. This object expects a separate bucket_name and object_key. However, BedrockInvokeModel expects an S3 URI. This mismatch is handled in the code by building an S3 URI from the S3 Location

https://github.com/aws/aws-cdk/blob/83aa3956ad035f534a7d96374844085919be3e8a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/bedrock/invoke-model.ts#L208-L213

The problem is that field references cannot be concatenated in this way, hence the error I see.

This makes the S3 integration basically unusable from the CDK, because the S3 locations must be hardcoded, which cannot work for any real world workload.

My suggestion is to extend BedrockInvokeModelInputProps and BedrockInvokeModelOutputProps to allow either the existing s3Location field to be used (for backwards compatibility), or a string field called s3Uri. If s3Uri were provided, it would be used directly, allowing for the use of JsonPaths for the URI.

Additional Information/Context

No response

CDK CLI Version

2.129.0 (build d5ab0df)

Framework Version

2.129.0

Node.js Version

v18.17.1

OS

Ubuntu (Windows Subsystem for Linux)

Language

TypeScript, Python, .NET, Java, Go

Language Version

Python 3.11.6

Other information

No response

SamStephens avatar Feb 23 '24 01:02 SamStephens

Thank you for the detailed feedback. Making it a p1 and we welcome any pull requests.

pahud avatar Feb 23 '24 17:02 pahud

Thanks @pahud . Unfortunately I'm unlikely to be in a position to do this myself, because we're not going to end up using this integration.

SamStephens avatar Feb 26 '24 01:02 SamStephens

Hi, I would like to investigate this issue, can I work on a PR?

clganidxr avatar Mar 25 '24 00:03 clganidxr

Hi @gm-al, Thank you for your interest to work on this issue. Please feel free to submit a PR.

godwingrs22 avatar Mar 25 '24 16:03 godwingrs22

Hello, is there any update on this ? Thank you very much

Celine999999 avatar May 15 '24 12:05 Celine999999

Hey @Celine999999 , Thank you for reaching out, i'll raise a PR shortly for this issue.

shikha372 avatar May 21 '24 17:05 shikha372

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. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] avatar Jul 24 '24 00:07 github-actions[bot]

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. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] avatar Jul 24 '24 00:07 github-actions[bot]