Closed1

BedrockAgentでClaude3.5 Sonnet V2を使用するCfnテンプレート

mirabulemirabule
  • us-east-1にBedrockAgentを作成する前提。
  • BedrockAgentでClaude3.5 sonnet v2を使用するために、Cross-region inferenceを使用する。
  • us-east-1とus-west-2でClaude3.5 sonnet v2のモデルアクセスを有効にする。
  • Modelは、Cross-region inferenceus.anthropic.claude-3-5-sonnet-20241022-v2:0を指定する。
CloudFormationテンプレート
AWSTemplateFormatVersion: "2010-09-09"
Description: bedrock agent

Parameters:
  Model:
    Type: String

Resources:

  BedrockAgentRole:
    Type: AWS::IAM::Role
    Properties:
      RoleName: !Sub "AmazonBedrockExecutionRoleForAgents_${AWS::StackName}"
      AssumeRolePolicyDocument:
        Version: 2012-10-17
        Statement:
          - Effect: Allow
            Principal:
              Service: bedrock.amazonaws.com
            Action: sts:AssumeRole
            Condition:
              StringEquals:
                aws:SourceAccount: !Sub ${AWS::AccountId}
              ArnLike:
                aws:SourceArn: !Sub arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:agent/*
      Policies:
        - PolicyName: AmazonBedrockExecutionRoleForAgents_FastAPISamplePolicy
          PolicyDocument:
            Version: 2012-10-17
            Statement:
              - Effect: Allow
                Action:
                  - bedrock:InvokeModel
                  - bedrock:GetInferenceProfile
                  - bedrock:GetFoundationModel
                Resource:
                  - !Sub arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:inference-profile/*
                  - arn:aws:bedrock:*::foundation-model/*

  BedrockAgent:
    Type: AWS::Bedrock::Agent
    Properties:
      AgentName: DemoAgent
      AgentResourceRoleArn: !GetAtt BedrockAgentRole.Arn
      FoundationModel: !Ref Model
      Instruction: |
        あなたは優秀なアシスタントです。
        質問内容を完全に理解してください。
        情報不足であれば、ユーザに追加情報を要求してください。
        質問には丁寧な日本語で回答してください。
      AutoPrepare: true
      ActionGroups:
        # AIがユーザに追加情報を要求する
        - ActionGroupName: UserInputAction
          ActionGroupState: ENABLED
          ParentActionGroupSignature: AMAZON.UserInput

  BedrockAgentAliasV1:
    Type: AWS::Bedrock::AgentAlias
    Properties:
      AgentAliasName: v1
      AgentId: !Ref BedrockAgent

  # Agentの修正をデプロイするときはAliasを追加すること。
  # 古いAliasは、ロールバック不要になったら、削除して良い。
  #BedrockAgentAliasV2:
  #  Type: AWS::Bedrock::AgentAlias
  #  Properties:
  #    AgentAliasName: v2
  #    AgentId: !Ref BedrockAgent
このスクラップは2025/02/02にクローズされました