AgentCore Code Interpreter セッションの開始
Code Interpreter を作成したら、セッションを開始してコードを実行できます。
例
- AWS CLI
-
-
CLI を使用して Code Interpreter AWS セッションを開始するには、
start-code-interpreter-sessionコマンドを使用します。aws bedrock-agentcore start-code-interpreter-session \ --region <Region> \ --code-interpreter-id "<your-code-interpreter-id>" \ --name "my-code-session" \ --description "My Code Interpreter session for data analysis" \ --session-timeout-seconds 900
-
- Boto3
-
-
AWS SDK for Python を使用して Code Interpreter セッションを開始するには、
start_code_interpreter_sessionメソッドを使用します。import boto3 # Initialize the boto3 client dp_client = boto3.client( 'bedrock-agentcore', region_name="<Region>", endpoint_url="https://bedrock-agentcore.<Region>.amazonaws.com" ) # Start a Code Interpreter session response = dp_client.start_code_interpreter_session( codeInterpreterIdentifier="aws.codeinterpreter.v1", name="sandbox-session-1", sessionTimeoutSeconds=3600 ) # Print the session ID session_id = response["sessionId"] print(f"Session created: {session_id}")
-
- API
-
-
API を使用して新しい Code Interpreter セッションを開始するには、次の呼び出しを使用します。
# Using awscurl awscurl -X PUT \ "https://bedrock-agentcore.<Region>.amazonaws.com/code-interpreters/aws.codeinterpreter.v1/sessions/start" \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ --service bedrock-agentcore \ --region <Region> \ -d '{ "name": "code-session-abc12345", "description": "code sandbox session", "sessionTimeoutSeconds": 900 }'注記
でコードインタープリタを作成することで、マネージドリソース ID
aws.codeinterpreter.v1または取得するリソース ID を使用できますCreateCodeInterpreter。
-
セッション管理
コードの実行