diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/bedrock/invoke-model.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/bedrock/invoke-model.ts index 03a7837560676..6d789ff85a356 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/bedrock/invoke-model.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/bedrock/invoke-model.ts @@ -188,11 +188,11 @@ export class BedrockInvokeModel extends sfn.TaskStateBase { if (props.output?.s3Location?.objectVersion !== undefined) { throw new Error('Output S3 object version is not supported.'); } - if (props.input?.s3InputUri && props.input.s3Location) { - throw new Error('Cannot specify both S3 InputUri and S3 location'); + if (props.input?.s3InputUri && props.input.s3Location || props.output?.s3OutputUri && props.output.s3Location) { + throw new Error('Either specify S3 Uri or S3 location, but not both.'); } - if (props.input?.s3InputUri === '') { - throw new Error('S3 InputUri cannot be an empty string'); + if (useNewS3UriParamsForTask && (props.input?.s3InputUri === '' || props.output?.s3OutputUri === '')) { + throw new Error('S3 Uri cannot be an empty string'); } //Warning to let users know about the newly introduced props diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/bedrock/invoke-model.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/bedrock/invoke-model.test.ts index e66cd7301e7d2..4b5fdb894dba4 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/bedrock/invoke-model.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/bedrock/invoke-model.test.ts @@ -394,6 +394,50 @@ describe('Invoke Model', () => { }); }); + test('throws error S3 input Uri is specified as an empty string', () => { + const app = new cdk.App({ context: { [cxapi.USE_NEW_S3URI_PARAMETERS_FOR_BEDROCK_INVOKE_MODEL_TASK]: true } }); + const stack = new cdk.Stack(app); + const model = bedrock.ProvisionedModel.fromProvisionedModelArn(stack, 'Imported', 'arn:aws:bedrock:us-turbo-2:123456789012:provisioned-model/abc-123'); + + expect(() => { + new BedrockInvokeModel(stack, 'Invoke', { + model, + input: { + s3InputUri: '', + }, + output: { + s3OutputUri: '', + }, + }); + }).toThrow('S3 Uri cannot be an empty string'); + }); + + test('cannot specify both s3 uri and s3 bucket', () => { + const app = new cdk.App({ context: { [cxapi.USE_NEW_S3URI_PARAMETERS_FOR_BEDROCK_INVOKE_MODEL_TASK]: true } }); + const stack = new cdk.Stack(app); + const model = bedrock.ProvisionedModel.fromProvisionedModelArn(stack, 'Imported', 'arn:aws:bedrock:us-turbo-2:123456789012:provisioned-model/abc-123'); + + expect(() => { + new BedrockInvokeModel(stack, 'Invoke', { + model, + input: { + s3Location: { + bucketName: 'test-bucket', + objectKey: 'input-key', + }, + s3InputUri: sfn.JsonPath.stringAt('$.prompt'), + }, + output: { + s3Location: { + bucketName: 'test-bucket', + objectKey: 'output-key', + }, + s3OutputUri: sfn.JsonPath.stringAt('$.prompt'), + }, + }); + }).toThrow('Either specify S3 Uri or S3 location, but not both.'); + }); + test('S3 permissions are created in generated policy when input and output locations are specified', () => { // GIVEN const stack = new cdk.Stack(); @@ -475,8 +519,8 @@ describe('Invoke Model', () => { // WHEN const task = new BedrockInvokeModel(stack, 'Invoke', { model, - input: { s3InputUri: sfn.JsonPath.stringAt('$.prompt') }, - output: { s3OutputUri: sfn.JsonPath.stringAt('$.prompt') }, + input: { s3InputUri: 's3://input-bucket/input-key' }, + output: { s3OutputUri: 's3://input-bucket/output-key' }, }); new sfn.StateMachine(stack, 'StateMachine', { diff --git a/packages/aws-cdk-lib/cx-api/FEATURE_FLAGS.md b/packages/aws-cdk-lib/cx-api/FEATURE_FLAGS.md index 87785d00f7478..105449326312a 100644 --- a/packages/aws-cdk-lib/cx-api/FEATURE_FLAGS.md +++ b/packages/aws-cdk-lib/cx-api/FEATURE_FLAGS.md @@ -72,7 +72,7 @@ Flags come in three types: | [@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm](#aws-cdkaws-ecsremovedefaultdeploymentalarm) | When enabled, remove default deployment alarm settings | 2.143.0 | (default) | | [@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault](#aws-cdkcustom-resourceslogapiresponsedatapropertytruedefault) | When enabled, the custom resource used for `AwsCustomResource` will configure the `logApiResponseData` property as true by default | 2.145.0 | (fix) | | [@aws-cdk/aws-s3:keepNotificationInImportedBucket](#aws-cdkaws-s3keepnotificationinimportedbucket) | When enabled, Adding notifications to a bucket in the current stack will not remove notification from imported stack. | 2.155.0 | (fix) | -| [@aws-cdk:aws-stepfunctions-tasks:useNewS3UriParametersForBedrockInvokeModelTask](#aws-cdkaws-stepfunctions-tasksusenews3uriparametersforbedrockinvokemodeltask) | When enabled, use new props for S3 URI field in task definition of state machine for bedrock invoke model. | 2.156.0 | (fix) | +| [@aws-cdk:aws-stepfunctions-tasks:useNewS3UriParametersForBedrockInvokeModelTask](#aws-cdkaws-stepfunctions-tasksusenews3uriparametersforbedrockinvokemodeltask) | When enabled, use new props for S3 URI field in task definition of state machine for bedrock invoke model. | V2NEXT | (fix) | @@ -1372,7 +1372,7 @@ When this feature flag is enabled, specify newly introduced props 's3InputUri' a | Since | Default | Recommended | | ----- | ----- | ----- | | (not in v1) | | | -| 2.156.0 | `true` | `true` | +| V2NEXT | `false` | `true` | diff --git a/packages/aws-cdk-lib/cx-api/lib/features.ts b/packages/aws-cdk-lib/cx-api/lib/features.ts index 9463ca7ca8848..db501b3ea03be 100644 --- a/packages/aws-cdk-lib/cx-api/lib/features.ts +++ b/packages/aws-cdk-lib/cx-api/lib/features.ts @@ -1121,7 +1121,7 @@ export const FLAGS: Record = { 's3OutputUri' to populate S3 uri under input and output fields in state machine task definition for Bedrock invoker model. `, - introducedIn: { v2: '2.155.1' }, + introducedIn: { v2: 'V2NEXT' }, recommendedValue: true, }, };