@@ -3559,6 +3559,69 @@ describe('#compileIamRole', () => {
3559
3559
} ] ) ;
3560
3560
} ) ;
3561
3561
3562
+ it ( 'should give bedrock invoke permissions for foundation models' , ( ) => {
3563
+ serverless . service . stepFunctions = {
3564
+ stateMachines : {
3565
+ myStateMachine1 : {
3566
+ id : 'StateMachine1' ,
3567
+ definition : {
3568
+ StartAt : 'A' ,
3569
+ States : {
3570
+ A : {
3571
+ Type : 'Task' ,
3572
+ Resource : 'arn:aws:states:::bedrock:invokeModel' ,
3573
+ Parameters : {
3574
+ ModelId : 'anthropic.claude-v2:1' ,
3575
+ Body : {
3576
+ prompt : 'your-prompt' ,
3577
+ max_tokens_to_sample : 500 ,
3578
+ temperature : 0.1 ,
3579
+ } ,
3580
+ ContentType : 'application/json' ,
3581
+ Accept : 'application/json' ,
3582
+ } ,
3583
+ Next : 'B' ,
3584
+ } ,
3585
+ B : {
3586
+ Type : 'Task' ,
3587
+ Resource : 'arn:aws:states:::bedrock:invokeModel' ,
3588
+ Parameters : {
3589
+ // modelId can be specified as an arn
3590
+ ModelId : 'arn:aws:bedrock:us-east-1::foundation-model/meta.llama2-70b-chat-v1' ,
3591
+ Body : {
3592
+ prompt : 'your-prompt' ,
3593
+ max_tokens_to_sample : 500 ,
3594
+ temperature : 0.1 ,
3595
+ } ,
3596
+ ContentType : 'application/json' ,
3597
+ Accept : 'application/json' ,
3598
+ } ,
3599
+ End : true ,
3600
+ } ,
3601
+ } ,
3602
+ } ,
3603
+ } ,
3604
+ } ,
3605
+ } ;
3606
+
3607
+ serverlessStepFunctions . compileIamRole ( ) ;
3608
+ const statements = serverlessStepFunctions . serverless . service
3609
+ . provider . compiledCloudFormationTemplate . Resources . StateMachine1Role
3610
+ . Properties . Policies [ 0 ] . PolicyDocument . Statement ;
3611
+ const bedrockPermissions = statements . filter ( s => _ . isEqual ( s . Action , [ 'bedrock:InvokeModel' ] ) ) ;
3612
+ expect ( bedrockPermissions ) . to . have . lengthOf ( 1 ) ;
3613
+ expect ( bedrockPermissions [ 0 ] . Resource ) . to . have . lengthOf ( 2 ) ;
3614
+ expect ( bedrockPermissions [ 0 ] . Resource ) . to . deep . eq ( [
3615
+ {
3616
+ 'Fn::Sub' : [
3617
+ 'arn:${AWS::Partition}:bedrock:${AWS::Region}::foundation-model/anthropic.claude-v2:1' ,
3618
+ { } ,
3619
+ ] ,
3620
+ } ,
3621
+ 'arn:aws:bedrock:us-east-1::foundation-model/meta.llama2-70b-chat-v1' ,
3622
+ ] ) ;
3623
+ } ) ;
3624
+
3562
3625
it ( 'should give event bridge putEvents permissions' , ( ) => {
3563
3626
const genStateMachine = id => ( {
3564
3627
id,
0 commit comments