创建 AgentCore 代码解释器
您可以使用 Amazon Bedrock AgentCore 控制台、 AWS CLI 或 AWS SDK 创建代码解释器。
例
- Console
-
-
====== 使用控制台创建代码解释器
-
在 https://console.aws.amazon.com/bedrock-agentcore/home#
处打开 AgentCore 控制台。 -
在导航窗格中,选择Built-in 工具。
-
选择 “创建代码解释器” 工具。
-
提供唯一的工具名称和可选的描述。
-
在 “网络设置” 下,选择以下选项之一:
-
沙盒-外部网络访问受限的环境
-
公共网络-允许访问公共互联网资源
-
-
在 “权限” 下,指定一个 IAM 运行时角色,该角色定义了代码解释器可以访问的 AWS 资源。
-
选择创建。
创建代码解释器工具后,控制台会显示有关该工具的重要细节:
-
- Tool Resource ARN
-
<Region>唯一标识代码解释器工具资源的亚马逊资源名称 (ARN)(例如,arn: aws: bedrock-agentcore:: 123456789012: code-inperter-custom)。interpreter/code
- Code Interpreter Tool ID
-
代码解释器工具的唯一标识符,用于 API 调用(例如,code-interpreter-custom-abc123)。
- IAM Role
-
代码解释器在执行代码时扮演的 IAM 角色,决定它可以访问哪些 AWS 资源。
- Network Mode
-
代码解释器(沙盒或公共)的网络配置。
- Creation Time
-
创建代码解释器工具的日期和时间。
- AWS CLI
-
-
要使用 AWS CLI 创建代码解释器,请使用以下
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 软件开发工具包创建代码解释器,请使用以下
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 创建新的代码解释器实例,请使用以下调用:
# 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" } }'
-