Skip to content

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

@SamStephens

Description

@SamStephens

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

Input: this.props.input?.s3Location ? {
S3Uri: `s3://${this.props.input.s3Location.bucketName}/${this.props.input.s3Location.objectKey}`,
} : undefined,
Output: this.props.output?.s3Location ? {
S3Uri: `s3://${this.props.output.s3Location.bucketName}/${this.props.output.s3Location.objectKey}`,
} : undefined,

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions