Skip to content

Commit

Permalink
update feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
shikha372 committed Sep 5, 2024
1 parent 33cd3bc commit 47d60bd
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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', {
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk-lib/cx-api/FEATURE_FLAGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |

<!-- END table -->

Expand Down Expand Up @@ -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` |


<!-- END details -->
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/cx-api/lib/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ export const FLAGS: Record<string, FlagInfo> = {
'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,
},
};
Expand Down

0 comments on commit 47d60bd

Please sign in to comment.