Skip to content

Commit 842ee15

Browse files
authored
revert(stepfunctions-tasks): "feat(stepfunctions-tasks): allow BedrockInvokeModel to use JsonPath" (#31308)
Reverts #30298 to resolve #31302 BREAKING CHANGE: Reverting the original PR will come with the following breaking changes * **stepfunctions-tasks:** The `BedrockInvokeModel.outputPath` parameter will no longer be an S3Uri
1 parent a6c2ad6 commit 842ee15

File tree

11 files changed

+19
-255
lines changed

11 files changed

+19
-255
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/InvokeModelDefaultTestDeployAssert9C0D2DFC.assets.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/aws-stepfunctions-tasks-bedrock-invoke-model-integ.assets.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/aws-stepfunctions-tasks-bedrock-invoke-model-integ.template.json

+2-33
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,6 @@
4141
]
4242
]
4343
}
44-
},
45-
{
46-
"Action": [
47-
"s3:GetObject",
48-
"s3:PutObject"
49-
],
50-
"Effect": "Allow",
51-
"Resource": {
52-
"Fn::Join": [
53-
"",
54-
[
55-
"arn:",
56-
{
57-
"Ref": "AWS::Partition"
58-
},
59-
":s3:::*"
60-
]
61-
]
62-
}
6344
}
6445
],
6546
"Version": "2012-10-17"
@@ -91,19 +72,7 @@
9172
{
9273
"Ref": "AWS::Region"
9374
},
94-
"::foundation-model/amazon.titan-text-express-v1\",\"Body\":{\"inputText\":\"Generate a list of five first names.\",\"textGenerationConfig\":{\"maxTokenCount\":100,\"temperature\":1}}}},\"Prompt2\":{\"Next\":\"Prompt3\",\"Type\":\"Task\",\"ResultPath\":\"$\",\"ResultSelector\":{\"names.$\":\"$.Body.results[0].outputText\"},\"Resource\":\"arn:",
95-
{
96-
"Ref": "AWS::Partition"
97-
},
98-
":states:::bedrock:invokeModel\",\"Parameters\":{\"ModelId\":\"arn:",
99-
{
100-
"Ref": "AWS::Partition"
101-
},
102-
":bedrock:",
103-
{
104-
"Ref": "AWS::Region"
105-
},
106-
"::foundation-model/amazon.titan-text-express-v1\",\"Body\":{\"inputText.$\":\"States.Format('Alphabetize this list of first names:\\n{}', $.names)\",\"textGenerationConfig\":{\"maxTokenCount\":100,\"temperature\":1}}}},\"Prompt3\":{\"End\":true,\"Type\":\"Task\",\"InputPath\":\"$.names\",\"OutputPath\":\"$.names\",\"Resource\":\"arn:",
75+
"::foundation-model/amazon.titan-text-express-v1\",\"Body\":{\"inputText\":\"Generate a list of five first names.\",\"textGenerationConfig\":{\"maxTokenCount\":100,\"temperature\":1}}}},\"Prompt2\":{\"End\":true,\"Type\":\"Task\",\"ResultPath\":\"$\",\"ResultSelector\":{\"names.$\":\"$.Body.results[0].outputText\"},\"Resource\":\"arn:",
10776
{
10877
"Ref": "AWS::Partition"
10978
},
@@ -115,7 +84,7 @@
11584
{
11685
"Ref": "AWS::Region"
11786
},
118-
"::foundation-model/amazon.titan-text-express-v1\",\"Input\":{\"S3Uri.$\":\"$.names\"},\"Output\":{\"S3Uri.$\":\"$.names\"}}}},\"TimeoutSeconds\":30}"
87+
"::foundation-model/amazon.titan-text-express-v1\",\"Body\":{\"inputText.$\":\"States.Format('Alphabetize this list of first names:\\n{}', $.names)\",\"textGenerationConfig\":{\"maxTokenCount\":100,\"temperature\":1}}}}},\"TimeoutSeconds\":30}"
11988
]
12089
]
12190
},

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/cdk.out

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/integ.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/manifest.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/tree.json

+2-41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,7 @@ const prompt2 = new BedrockInvokeModel(stack, 'Prompt2', {
5252
resultPath: '$',
5353
});
5454

55-
const prompt3 = new BedrockInvokeModel(stack, 'Prompt3', {
56-
model,
57-
inputPath: sfn.JsonPath.stringAt('$.names'),
58-
outputPath: sfn.JsonPath.stringAt('$.names'),
59-
});
60-
61-
const chain = sfn.Chain.start(prompt1).next(prompt2).next(prompt3);
55+
const chain = sfn.Chain.start(prompt1).next(prompt2);
6256

6357
new sfn.StateMachine(stack, 'StateMachine', {
6458
definitionBody: sfn.DefinitionBody.fromChainable(chain),

packages/aws-cdk-lib/aws-stepfunctions-tasks/README.md

-21
Original file line numberDiff line numberDiff line change
@@ -398,27 +398,6 @@ const task = new tasks.BedrockInvokeModel(this, 'Prompt Model', {
398398
names: sfn.JsonPath.stringAt('$.Body.results[0].outputText'),
399399
},
400400
});
401-
```
402-
### Using Input Path
403-
404-
Provide S3 URI as an input or output path to invoke a model
405-
406-
```ts
407-
408-
import * as bedrock from 'aws-cdk-lib/aws-bedrock';
409-
410-
const model = bedrock.FoundationModel.fromFoundationModelId(
411-
this,
412-
'Model',
413-
bedrock.FoundationModelIdentifier.AMAZON_TITAN_TEXT_G1_EXPRESS_V1,
414-
);
415-
416-
const task = new tasks.BedrockInvokeModel(this, 'Prompt Model', {
417-
model,
418-
inputPath: sfn.JsonPath.stringAt('$.prompt'),
419-
outputPath: sfn.JsonPath.stringAt('$.prompt'),
420-
});
421-
422401
```
423402

424403
You can apply a guardrail to the invocation by setting `guardrail`.

packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/bedrock/invoke-model.ts

+6-37
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,12 @@ export class BedrockInvokeModel extends sfn.TaskStateBase {
140140

141141
constructor(scope: Construct, id: string, private readonly props: BedrockInvokeModelProps) {
142142
super(scope, id, props);
143-
144143
this.integrationPattern = props.integrationPattern ?? sfn.IntegrationPattern.REQUEST_RESPONSE;
145144

146145
validatePatternSupported(this.integrationPattern, BedrockInvokeModel.SUPPORTED_INTEGRATION_PATTERNS);
147146

148147
const isBodySpecified = props.body !== undefined;
149-
//Either specific props.input with bucket name and object key or input s3 path
150-
const isInputSpecified = (props.input !== undefined && props.input.s3Location !== undefined) || (props.inputPath !== undefined);
148+
const isInputSpecified = props.input !== undefined && props.input.s3Location !== undefined;
151149

152150
if (isBodySpecified && isInputSpecified) {
153151
throw new Error('Either `body` or `input` must be specified, but not both.');
@@ -173,21 +171,7 @@ export class BedrockInvokeModel extends sfn.TaskStateBase {
173171
}),
174172
];
175173

176-
if (this.props.inputPath !== undefined) {
177-
policyStatements.push(
178-
new iam.PolicyStatement({
179-
actions: ['s3:GetObject'],
180-
resources: [
181-
Stack.of(this).formatArn({
182-
region: '',
183-
account: '',
184-
service: 's3',
185-
resource: '*',
186-
}),
187-
],
188-
}),
189-
);
190-
} else if (this.props.input !== undefined && this.props.input.s3Location !== undefined) {
174+
if (this.props.input !== undefined && this.props.input.s3Location !== undefined) {
191175
policyStatements.push(
192176
new iam.PolicyStatement({
193177
actions: ['s3:GetObject'],
@@ -204,21 +188,7 @@ export class BedrockInvokeModel extends sfn.TaskStateBase {
204188
);
205189
}
206190

207-
if (this.props.outputPath !== undefined) {
208-
policyStatements.push(
209-
new iam.PolicyStatement({
210-
actions: ['s3:PutObject'],
211-
resources: [
212-
Stack.of(this).formatArn({
213-
region: '',
214-
account: '',
215-
service: 's3',
216-
resource: '*',
217-
}),
218-
],
219-
}),
220-
);
221-
} else if (this.props.output !== undefined && this.props.output.s3Location !== undefined) {
191+
if (this.props.output !== undefined && this.props.output.s3Location !== undefined) {
222192
policyStatements.push(
223193
new iam.PolicyStatement({
224194
actions: ['s3:PutObject'],
@@ -271,10 +241,10 @@ export class BedrockInvokeModel extends sfn.TaskStateBase {
271241
Body: this.props.body?.value,
272242
Input: this.props.input?.s3Location ? {
273243
S3Uri: `s3://${this.props.input.s3Location.bucketName}/${this.props.input.s3Location.objectKey}`,
274-
} : this.props.inputPath ? { S3Uri: this.props.inputPath } : undefined,
244+
} : undefined,
275245
Output: this.props.output?.s3Location ? {
276246
S3Uri: `s3://${this.props.output.s3Location.bucketName}/${this.props.output.s3Location.objectKey}`,
277-
} : this.props.outputPath ? { S3Uri: this.props.outputPath }: undefined,
247+
} : undefined,
278248
GuardrailIdentifier: this.props.guardrail?.guardrailIdentifier,
279249
GuardrailVersion: this.props.guardrail?.guardrailVersion,
280250
Trace: this.props.traceEnabled === undefined
@@ -284,6 +254,5 @@ export class BedrockInvokeModel extends sfn.TaskStateBase {
284254
: 'DISABLED',
285255
}),
286256
};
287-
};
257+
}
288258
}
289-

0 commit comments

Comments
 (0)