AgentCore コードインタープリタの作成
Amazon Bedrock AgentCore コンソール、 AWS CLI、または AWS SDK を使用してコードインタープリタを作成できます。
例
- Console
-
-
====== コンソールを使用してコードインタープリタを作成するには
-
https://console.aws.amazon.com/bedrock-agentcore/home#
で AgentCore コンソールを開きます。 -
ナビゲーションペインで、組み込みツールを選択します。
-
コードインタープリタツールの作成を選択します。
-
一意のツール名とオプションの Description を指定します。
-
ネットワーク設定 で、次のいずれかのオプションを選択します。
-
サンドボックス - 外部ネットワークアクセスが制限された環境
-
パブリックネットワーク - パブリックインターネットリソースへのアクセスを許可します
-
-
アクセス許可 で、Code Interpreter がアクセスできる AWS リソースを定義する IAM ランタイムロールを指定します。
-
[作成] を選択します。
Code Interpreter ツールを作成すると、コンソールにツールに関する重要な詳細が表示されます。
-
- Tool Resource ARN
-
Code Interpreter ツールリソースを一意に識別する Amazon リソースネーム (ARN) (例: arn:aws:bedrock-agentcore:<Region>:123456789012:code-interpreter/code-interpreter-custom)。
- Code Interpreter Tool ID
-
API コールで使用される Code Interpreter ツールの一意の識別子 (例: code-interpreter-custom-abc123)。
- IAM Role
-
Code Interpreter がコードを実行し、アクセスできる AWS リソースを決定する際に引き受ける IAM ロール。
- Network Mode
-
Code Interpreter (サンドボックスまたはパブリック) のネットワーク設定。
- Creation Time
-
Code Interpreter ツールが作成された日時。
- AWS CLI
-
-
CLI を使用して Code Interpreter AWS を作成するには、
create-code-interpreterコマンドを使用します。aws bedrock-agentcore create-code-interpreter \ --region <Region> \ --name "my-code-interpreter" \ --description "My Code Interpreter for data analysis" \ --network-configuration '{ "networkMode": "PUBLIC" }' \ --execution-role-arn "arn:aws:iam::123456789012:role/my-execution-role"
-
- Boto3
-
-
AWS SDK for Python を使用してコードインタープリタを作成するには、
create_code_interpreterメソッドを使用します。import boto3 # Initialize the boto3 client cp_client = boto3.client( 'bedrock-agentcore-control', region_name="<Region>", endpoint_url="https://bedrock-agentcore-control.<Region>.amazonaws.com" ) # Create a Code Interpreter response = cp_client.create_code_interpreter( name="myTestSandbox1", description="Test code sandbox for development", executionRoleArn="arn:aws:iam::123456789012:role/my-execution-role", networkConfiguration={ "networkMode": "PUBLIC" } ) # Print the Code Interpreter ID code_interpreter_id = response["codeInterpreterId"] print(f"Code Interpreter ID: {code_interpreter_id}")
-
- API
-
-
API を使用して新しい Code Interpreter インスタンスを作成するには、次の呼び出しを使用します。
# Using awscurl awscurl -X PUT "https://bedrock-agentcore-control.<Region>.amazonaws.com/code-interpreters" \ -H "Content-Type: application/json" \ --region <Region> \ --service bedrock-agentcore \ -d '{ "name": "codeinterpreter'$(date +%m%d%H%M%S)'", "description": "Test code sandbox for development", "executionRoleArn": "'${ROLE_ARN}'", "networkConfiguration": { "networkMode": "PUBLIC" } }'
-