From 4ddc702236e74abd179b5d866614066f71a0f91b Mon Sep 17 00:00:00 2001 From: "Kenta Goto (k.goto)" <24818752+go-to-k@users.noreply.github.com> Date: Fri, 27 Sep 2024 01:57:46 +0900 Subject: [PATCH] feat(bedrock): support meta llama3-2 (#31568) ### Issue # (if applicable) Closes #. ### Reason for this change Added Meta Llama 3.2 models. - meta.llama3-2-1b-instruct-v1:0 - meta.llama3-2-3b-instruct-v1:0 - meta.llama3-2-11b-instruct-v1:0 - meta.llama3-2-90b-instruct-v1:0 ref - https://aws.amazon.com/about-aws/whats-new/2024/09/llama-3-2-generative-ai-models-amazon-bedrock/ - https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html ### Description of changes Added the models. ### Description of how you validated changes ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- ...efaultTestDeployAssert9C0D2DFC.assets.json | 2 +- ...sks-bedrock-invoke-model-integ.assets.json | 6 +- ...s-bedrock-invoke-model-integ.template.json | 195 ++++++++++ .../integ.invoke-model.js.snapshot/cdk.out | 2 +- .../integ.invoke-model.js.snapshot/integ.json | 2 +- .../manifest.json | 24 +- .../integ.invoke-model.js.snapshot/tree.json | 355 ++++++++++++++++-- .../test/bedrock/integ.invoke-model.ts | 74 ++++ .../aws-bedrock/lib/foundation-model.ts | 12 + 9 files changed, 628 insertions(+), 44 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/InvokeModelDefaultTestDeployAssert9C0D2DFC.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/InvokeModelDefaultTestDeployAssert9C0D2DFC.assets.json index 81419156e1160..cd4b08517baee 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/InvokeModelDefaultTestDeployAssert9C0D2DFC.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/InvokeModelDefaultTestDeployAssert9C0D2DFC.assets.json @@ -1,5 +1,5 @@ { - "version": "36.0.5", + "version": "38.0.1", "files": { "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { "source": { diff --git a/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 b/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 index aab5d8193de11..3f8ec0ac28a11 100644 --- a/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 +++ b/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 @@ -1,7 +1,7 @@ { - "version": "36.0.5", + "version": "38.0.1", "files": { - "b6d22af12502fb22f7fee80b3981c8767eb09e8e9f4ab927a380544cdcdc384b": { + "582882a43e46336bf196e3d6ce641f77b803ad0beb1c85f9944a32aca0947480": { "source": { "path": "aws-stepfunctions-tasks-bedrock-invoke-model-integ.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "b6d22af12502fb22f7fee80b3981c8767eb09e8e9f4ab927a380544cdcdc384b.json", + "objectKey": "582882a43e46336bf196e3d6ce641f77b803ad0beb1c85f9944a32aca0947480.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/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 b/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 index ce041c6ffeaac..5615f72247915 100644 --- a/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 +++ b/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 @@ -144,6 +144,201 @@ ], "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" + }, + "LlamaStateMachineRoleA1E51172": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "states.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "LlamaStateMachineRoleDefaultPolicy36666B63": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "bedrock:InvokeModel", + "Effect": "Allow", + "Resource": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":bedrock:", + { + "Ref": "AWS::Region" + }, + "::foundation-model/meta.llama3-2-11b-instruct-v1:0" + ] + ] + }, + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":bedrock:", + { + "Ref": "AWS::Region" + }, + "::foundation-model/meta.llama3-2-1b-instruct-v1:0" + ] + ] + }, + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":bedrock:", + { + "Ref": "AWS::Region" + }, + "::foundation-model/meta.llama3-2-3b-instruct-v1:0" + ] + ] + }, + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":bedrock:", + { + "Ref": "AWS::Region" + }, + "::foundation-model/meta.llama3-2-90b-instruct-v1:0" + ] + ] + } + ] + }, + { + "Action": [ + "s3:GetObject", + "s3:PutObject" + ], + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":s3:::*" + ] + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "LlamaStateMachineRoleDefaultPolicy36666B63", + "Roles": [ + { + "Ref": "LlamaStateMachineRoleA1E51172" + } + ] + } + }, + "LlamaStateMachineD0B74BA3": { + "Type": "AWS::StepFunctions::StateMachine", + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "", + [ + "{\"StartAt\":\"LlamaPrompt1\",\"States\":{\"LlamaPrompt1\":{\"Next\":\"LlamaPrompt2\",\"Type\":\"Task\",\"ResultPath\":\"$\",\"ResultSelector\":{\"names.$\":\"$.Body.results[0].outputText\"},\"Resource\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":states:::bedrock:invokeModel\",\"Parameters\":{\"ModelId\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":bedrock:", + { + "Ref": "AWS::Region" + }, + "::foundation-model/meta.llama3-2-1b-instruct-v1:0\",\"Body\":{\"inputText\":\"Generate a list of five first names.\",\"textGenerationConfig\":{\"maxTokenCount\":100,\"temperature\":1}}}},\"LlamaPrompt2\":{\"Next\":\"LlamaPrompt3\",\"Type\":\"Task\",\"ResultPath\":\"$\",\"ResultSelector\":{\"names.$\":\"$.Body.results[0].outputText\"},\"Resource\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":states:::bedrock:invokeModel\",\"Parameters\":{\"ModelId\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":bedrock:", + { + "Ref": "AWS::Region" + }, + "::foundation-model/meta.llama3-2-3b-instruct-v1:0\",\"Body\":{\"inputText.$\":\"States.Format('Alphabetize this list of first names:/n{}', $.names)\",\"textGenerationConfig\":{\"maxTokenCount\":100,\"temperature\":1}}}},\"LlamaPrompt3\":{\"Next\":\"LlamaPrompt4\",\"Type\":\"Task\",\"OutputPath\":\"$.Body.results[0].outputText\",\"Resource\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":states:::bedrock:invokeModel\",\"Parameters\":{\"ModelId\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":bedrock:", + { + "Ref": "AWS::Region" + }, + "::foundation-model/meta.llama3-2-11b-instruct-v1:0\",\"Body\":{\"inputText.$\":\"States.Format('Echo list of first names: {}', $.names)\",\"textGenerationConfig\":{\"maxTokenCount\":100,\"temperature\":1}}}},\"LlamaPrompt4\":{\"End\":true,\"Type\":\"Task\",\"Resource\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":states:::bedrock:invokeModel\",\"Parameters\":{\"ModelId\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":bedrock:", + { + "Ref": "AWS::Region" + }, + "::foundation-model/meta.llama3-2-90b-instruct-v1:0\",\"Input\":{\"S3Uri\":\"$.names\"},\"Output\":{\"S3Uri\":\"$.names\"}}}},\"TimeoutSeconds\":30}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "LlamaStateMachineRoleA1E51172", + "Arn" + ] + } + }, + "DependsOn": [ + "LlamaStateMachineRoleDefaultPolicy36666B63", + "LlamaStateMachineRoleA1E51172" + ], + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" } }, "Parameters": { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/cdk.out index bd5311dc372de..c6e612584e352 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/cdk.out +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/cdk.out @@ -1 +1 @@ -{"version":"36.0.5"} \ No newline at end of file +{"version":"38.0.1"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/integ.json index 6e638249caa25..f67d359eecd73 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/integ.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/integ.json @@ -1,5 +1,5 @@ { - "version": "36.0.5", + "version": "38.0.1", "testCases": { "InvokeModel/DefaultTest": { "stacks": [ diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/manifest.json index 085c560bba157..f0640d0e36738 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/manifest.json @@ -1,5 +1,5 @@ { - "version": "36.0.5", + "version": "38.0.1", "artifacts": { "aws-stepfunctions-tasks-bedrock-invoke-model-integ.assets": { "type": "cdk:asset-manifest", @@ -16,9 +16,10 @@ "templateFile": "aws-stepfunctions-tasks-bedrock-invoke-model-integ.template.json", "terminationProtection": false, "validateOnSynth": false, + "notificationArns": [], "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/b6d22af12502fb22f7fee80b3981c8767eb09e8e9f4ab927a380544cdcdc384b.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/582882a43e46336bf196e3d6ce641f77b803ad0beb1c85f9944a32aca0947480.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -52,6 +53,24 @@ "data": "StateMachine2E01A3A5" } ], + "/aws-stepfunctions-tasks-bedrock-invoke-model-integ/LlamaStateMachine/Role/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "LlamaStateMachineRoleA1E51172" + } + ], + "/aws-stepfunctions-tasks-bedrock-invoke-model-integ/LlamaStateMachine/Role/DefaultPolicy/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "LlamaStateMachineRoleDefaultPolicy36666B63" + } + ], + "/aws-stepfunctions-tasks-bedrock-invoke-model-integ/LlamaStateMachine/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "LlamaStateMachineD0B74BA3" + } + ], "/aws-stepfunctions-tasks-bedrock-invoke-model-integ/BootstrapVersion": [ { "type": "aws:cdk:logicalId", @@ -82,6 +101,7 @@ "templateFile": "InvokeModelDefaultTestDeployAssert9C0D2DFC.template.json", "terminationProtection": false, "validateOnSynth": false, + "notificationArns": [], "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/tree.json index 217a79721df41..13e1e0dcb23a3 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.js.snapshot/tree.json @@ -12,32 +12,32 @@ "id": "Prompt1", "path": "aws-stepfunctions-tasks-bedrock-invoke-model-integ/Prompt1", "constructInfo": { - "fqn": "aws-cdk-lib.aws_stepfunctions_tasks.BedrockInvokeModel", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "Prompt2": { "id": "Prompt2", "path": "aws-stepfunctions-tasks-bedrock-invoke-model-integ/Prompt2", "constructInfo": { - "fqn": "aws-cdk-lib.aws_stepfunctions_tasks.BedrockInvokeModel", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "Prompt3": { "id": "Prompt3", "path": "aws-stepfunctions-tasks-bedrock-invoke-model-integ/Prompt3", "constructInfo": { - "fqn": "aws-cdk-lib.aws_stepfunctions_tasks.BedrockInvokeModel", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "Prompt4": { "id": "Prompt4", "path": "aws-stepfunctions-tasks-bedrock-invoke-model-integ/Prompt4", "constructInfo": { - "fqn": "aws-cdk-lib.aws_stepfunctions_tasks.BedrockInvokeModel", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "StateMachine": { @@ -52,8 +52,8 @@ "id": "ImportRole", "path": "aws-stepfunctions-tasks-bedrock-invoke-model-integ/StateMachine/Role/ImportRole", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "Resource": { @@ -77,8 +77,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.CfnRole", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "DefaultPolicy": { @@ -144,20 +144,20 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.CfnPolicy", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.Policy", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.Role", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "Resource": { @@ -231,36 +231,319 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_stepfunctions.CfnStateMachine", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_stepfunctions.StateMachine", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "LlamaPrompt1": { + "id": "LlamaPrompt1", + "path": "aws-stepfunctions-tasks-bedrock-invoke-model-integ/LlamaPrompt1", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "LlamaPrompt2": { + "id": "LlamaPrompt2", + "path": "aws-stepfunctions-tasks-bedrock-invoke-model-integ/LlamaPrompt2", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "LlamaPrompt3": { + "id": "LlamaPrompt3", + "path": "aws-stepfunctions-tasks-bedrock-invoke-model-integ/LlamaPrompt3", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "LlamaPrompt4": { + "id": "LlamaPrompt4", + "path": "aws-stepfunctions-tasks-bedrock-invoke-model-integ/LlamaPrompt4", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "LlamaStateMachine": { + "id": "LlamaStateMachine", + "path": "aws-stepfunctions-tasks-bedrock-invoke-model-integ/LlamaStateMachine", + "children": { + "Role": { + "id": "Role", + "path": "aws-stepfunctions-tasks-bedrock-invoke-model-integ/LlamaStateMachine/Role", + "children": { + "ImportRole": { + "id": "ImportRole", + "path": "aws-stepfunctions-tasks-bedrock-invoke-model-integ/LlamaStateMachine/Role/ImportRole", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "Resource": { + "id": "Resource", + "path": "aws-stepfunctions-tasks-bedrock-invoke-model-integ/LlamaStateMachine/Role/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "states.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DefaultPolicy": { + "id": "DefaultPolicy", + "path": "aws-stepfunctions-tasks-bedrock-invoke-model-integ/LlamaStateMachine/Role/DefaultPolicy", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-stepfunctions-tasks-bedrock-invoke-model-integ/LlamaStateMachine/Role/DefaultPolicy/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Policy", + "aws:cdk:cloudformation:props": { + "policyDocument": { + "Statement": [ + { + "Action": "bedrock:InvokeModel", + "Effect": "Allow", + "Resource": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":bedrock:", + { + "Ref": "AWS::Region" + }, + "::foundation-model/meta.llama3-2-11b-instruct-v1:0" + ] + ] + }, + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":bedrock:", + { + "Ref": "AWS::Region" + }, + "::foundation-model/meta.llama3-2-1b-instruct-v1:0" + ] + ] + }, + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":bedrock:", + { + "Ref": "AWS::Region" + }, + "::foundation-model/meta.llama3-2-3b-instruct-v1:0" + ] + ] + }, + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":bedrock:", + { + "Ref": "AWS::Region" + }, + "::foundation-model/meta.llama3-2-90b-instruct-v1:0" + ] + ] + } + ] + }, + { + "Action": [ + "s3:GetObject", + "s3:PutObject" + ], + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":s3:::*" + ] + ] + } + } + ], + "Version": "2012-10-17" + }, + "policyName": "LlamaStateMachineRoleDefaultPolicy36666B63", + "roles": [ + { + "Ref": "LlamaStateMachineRoleA1E51172" + } + ] + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "Resource": { + "id": "Resource", + "path": "aws-stepfunctions-tasks-bedrock-invoke-model-integ/LlamaStateMachine/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::StepFunctions::StateMachine", + "aws:cdk:cloudformation:props": { + "definitionString": { + "Fn::Join": [ + "", + [ + "{\"StartAt\":\"LlamaPrompt1\",\"States\":{\"LlamaPrompt1\":{\"Next\":\"LlamaPrompt2\",\"Type\":\"Task\",\"ResultPath\":\"$\",\"ResultSelector\":{\"names.$\":\"$.Body.results[0].outputText\"},\"Resource\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":states:::bedrock:invokeModel\",\"Parameters\":{\"ModelId\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":bedrock:", + { + "Ref": "AWS::Region" + }, + "::foundation-model/meta.llama3-2-1b-instruct-v1:0\",\"Body\":{\"inputText\":\"Generate a list of five first names.\",\"textGenerationConfig\":{\"maxTokenCount\":100,\"temperature\":1}}}},\"LlamaPrompt2\":{\"Next\":\"LlamaPrompt3\",\"Type\":\"Task\",\"ResultPath\":\"$\",\"ResultSelector\":{\"names.$\":\"$.Body.results[0].outputText\"},\"Resource\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":states:::bedrock:invokeModel\",\"Parameters\":{\"ModelId\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":bedrock:", + { + "Ref": "AWS::Region" + }, + "::foundation-model/meta.llama3-2-3b-instruct-v1:0\",\"Body\":{\"inputText.$\":\"States.Format('Alphabetize this list of first names:/n{}', $.names)\",\"textGenerationConfig\":{\"maxTokenCount\":100,\"temperature\":1}}}},\"LlamaPrompt3\":{\"Next\":\"LlamaPrompt4\",\"Type\":\"Task\",\"OutputPath\":\"$.Body.results[0].outputText\",\"Resource\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":states:::bedrock:invokeModel\",\"Parameters\":{\"ModelId\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":bedrock:", + { + "Ref": "AWS::Region" + }, + "::foundation-model/meta.llama3-2-11b-instruct-v1:0\",\"Body\":{\"inputText.$\":\"States.Format('Echo list of first names: {}', $.names)\",\"textGenerationConfig\":{\"maxTokenCount\":100,\"temperature\":1}}}},\"LlamaPrompt4\":{\"End\":true,\"Type\":\"Task\",\"Resource\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":states:::bedrock:invokeModel\",\"Parameters\":{\"ModelId\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":bedrock:", + { + "Ref": "AWS::Region" + }, + "::foundation-model/meta.llama3-2-90b-instruct-v1:0\",\"Input\":{\"S3Uri\":\"$.names\"},\"Output\":{\"S3Uri\":\"$.names\"}}}},\"TimeoutSeconds\":30}" + ] + ] + }, + "roleArn": { + "Fn::GetAtt": [ + "LlamaStateMachineRoleA1E51172", + "Arn" + ] + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "BootstrapVersion": { "id": "BootstrapVersion", "path": "aws-stepfunctions-tasks-bedrock-invoke-model-integ/BootstrapVersion", "constructInfo": { - "fqn": "aws-cdk-lib.CfnParameter", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "CheckBootstrapVersion": { "id": "CheckBootstrapVersion", "path": "aws-stepfunctions-tasks-bedrock-invoke-model-integ/CheckBootstrapVersion", "constructInfo": { - "fqn": "aws-cdk-lib.CfnRule", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.Stack", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "InvokeModel": { @@ -287,22 +570,22 @@ "id": "BootstrapVersion", "path": "InvokeModel/DefaultTest/DeployAssert/BootstrapVersion", "constructInfo": { - "fqn": "aws-cdk-lib.CfnParameter", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "CheckBootstrapVersion": { "id": "CheckBootstrapVersion", "path": "InvokeModel/DefaultTest/DeployAssert/CheckBootstrapVersion", "constructInfo": { - "fqn": "aws-cdk-lib.CfnRule", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.Stack", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, @@ -327,8 +610,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.App", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } } \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.ts index 7ae58db6d8692..a0f2118867e1e 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-stepfunctions-tasks/test/bedrock/integ.invoke-model.ts @@ -85,6 +85,80 @@ new sfn.StateMachine(stack, 'StateMachine', { timeout: cdk.Duration.seconds(30), }); +const llamaModel1 = bedrock.FoundationModel.fromFoundationModelId(stack, 'LlamaModel1', bedrock.FoundationModelIdentifier.META_LLAMA_3_2_1B_INSTRUCT_V1); +const llamaPrompt1 = new BedrockInvokeModel(stack, 'LlamaPrompt1', { + model: llamaModel1, + body: sfn.TaskInput.fromObject( + { + inputText: 'Generate a list of five first names.', + textGenerationConfig: { + maxTokenCount: 100, + temperature: 1, + }, + }, + ), + resultSelector: { + names: sfn.JsonPath.stringAt('$.Body.results[0].outputText'), + }, + resultPath: '$', +}); + +const llamaModel2 = bedrock.FoundationModel.fromFoundationModelId(stack, 'LlamaModel2', bedrock.FoundationModelIdentifier.META_LLAMA_3_2_3B_INSTRUCT_V1); +const llamaPrompt2 = new BedrockInvokeModel(stack, 'LlamaPrompt2', { + model: llamaModel2, + body: sfn.TaskInput.fromObject( + { + inputText: sfn.JsonPath.format( + 'Alphabetize this list of first names:/n{}', + sfn.JsonPath.stringAt('$.names'), + ), + textGenerationConfig: { + maxTokenCount: 100, + temperature: 1, + }, + }, + ), + resultSelector: { + names: sfn.JsonPath.stringAt('$.Body.results[0].outputText'), + }, + resultPath: '$', +}); + +/** Test for Bedrock Output Path */ +const llamaModel3 = bedrock.FoundationModel.fromFoundationModelId(stack, 'LlamaModel3', bedrock.FoundationModelIdentifier.META_LLAMA_3_2_11B_INSTRUCT_V1); +const llamaPrompt3 = new BedrockInvokeModel(stack, 'LlamaPrompt3', { + model: llamaModel3, + body: sfn.TaskInput.fromObject( + { + inputText: sfn.JsonPath.format( + 'Echo list of first names: {}', + sfn.JsonPath.stringAt('$.names'), + ), + textGenerationConfig: { + maxTokenCount: 100, + temperature: 1, + }, + }, + ), + outputPath: '$.Body.results[0].outputText', +}); + +/** Test for Bedrock s3 URI Path */ +//State Machine Execution will fail for the following input as it expects a valid s3 URI from previous prompt +const llamaModel4 = bedrock.FoundationModel.fromFoundationModelId(stack, 'LlamaModel4', bedrock.FoundationModelIdentifier.META_LLAMA_3_2_90B_INSTRUCT_V1); +const llamaPrompt4 = new BedrockInvokeModel(stack, 'LlamaPrompt4', { + model: llamaModel4, + input: { s3InputUri: '$.names' }, + output: { s3OutputUri: '$.names' }, +}); + +const llamaChain = sfn.Chain.start(llamaPrompt1).next(llamaPrompt2).next(llamaPrompt3).next(llamaPrompt4); + +new sfn.StateMachine(stack, 'LlamaStateMachine', { + definitionBody: sfn.DefinitionBody.fromChainable(llamaChain), + timeout: cdk.Duration.seconds(30), +}); + new IntegTest(app, 'InvokeModel', { testCases: [stack], }); diff --git a/packages/aws-cdk-lib/aws-bedrock/lib/foundation-model.ts b/packages/aws-cdk-lib/aws-bedrock/lib/foundation-model.ts index 6d58fee9c0f5b..5b4e5ad809b59 100644 --- a/packages/aws-cdk-lib/aws-bedrock/lib/foundation-model.ts +++ b/packages/aws-cdk-lib/aws-bedrock/lib/foundation-model.ts @@ -206,6 +206,18 @@ export class FoundationModelIdentifier { /** Base model "meta.llama3-1-405b-instruct-v1:0". */ public static readonly META_LLAMA_3_1_405_INSTRUCT_V1 = new FoundationModelIdentifier('meta.llama3-1-405b-instruct-v1:0'); + /** Base model "meta.llama3-2-1b-instruct-v1:0". */ + public static readonly META_LLAMA_3_2_1B_INSTRUCT_V1 = new FoundationModelIdentifier('meta.llama3-2-1b-instruct-v1:0'); + + /** Base model "meta.llama3-2-3b-instruct-v1:0". */ + public static readonly META_LLAMA_3_2_3B_INSTRUCT_V1 = new FoundationModelIdentifier('meta.llama3-2-3b-instruct-v1:0'); + + /** Base model "meta.llama3-2-11b-instruct-v1:0". */ + public static readonly META_LLAMA_3_2_11B_INSTRUCT_V1 = new FoundationModelIdentifier('meta.llama3-2-11b-instruct-v1:0'); + + /** Base model "meta.llama3-2-90b-instruct-v1:0". */ + public static readonly META_LLAMA_3_2_90B_INSTRUCT_V1 = new FoundationModelIdentifier('meta.llama3-2-90b-instruct-v1:0'); + /** Base model "mistral.mistral-7b-instruct-v0:2". */ public static readonly MISTRAL_MISTRAL_7B_INSTRUCT_V0_2 = new FoundationModelIdentifier('mistral.mistral-7b-instruct-v0:2');