建立 AgentCore 程式碼解譯器
您可以使用 Amazon Bedrock AgentCore 主控台、 AWS CLI 或 AWS SDK 建立程式碼解譯器。
範例
- Console
-
-
====== 使用主控台建立程式碼解譯器
-
在 https://# 開啟 AgentCore 主控台。 https://console.aws.amazon.com/bedrock-agentcore/home
-
在導覽窗格中,選擇內建工具。
-
選擇建立程式碼解譯器工具。
-
提供唯一的工具名稱和選用的描述。
-
在網路設定 下,選擇下列其中一個選項:
-
沙盒 - 具有有限外部網路存取的環境
-
公有網路 - 允許存取公有網際網路資源
-
-
在許可 下,指定 IAM 執行期角色,以定義程式碼解譯器可存取 AWS 的資源。
-
選擇建立。
建立程式碼解譯器工具後,主控台會顯示工具的重要詳細資訊:
-
- Tool Resource ARN
-
可唯一識別 Code Interpreter 工具資源的 Amazon Resource Name (ARN) (例如 arn:aws:bedrock-agentcore:<Region>:123456789012:code-interpreter/code-interpreter-custom)。
- Code Interpreter Tool ID
-
Code Interpreter 工具的唯一識別符,用於 API 呼叫 (例如 code-interpreter-custom-abc123)。
- IAM Role
-
Code Interpreter 在執行程式碼時擔任的 IAM 角色,決定可以存取哪些 AWS 資源。
- Network Mode
-
Code Interpreter (Sandbox 或 Public) 的網路組態。
- Creation Time
-
建立 Code Interpreter 工具的日期和時間。
- AWS CLI
-
-
若要使用 CLI 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
-
-
若要使用適用於 Python 的 AWS SDK 建立程式碼解譯器,請使用
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" } }'
-