View a markdown version of this page

停止 AgentCore 代码解释器会话 - Amazon Bedrock AgentCore

停止 AgentCore 代码解释器会话

使用完代码解释器会话后,应停止该会话以释放资源并避免不必要的费用。

AWS CLI
  1. 要使用 AWS CLI 停止代码解释器会话,请使用以下stop-code-interpreter-session命令:

    aws bedrock-agentcore stop-code-interpreter-session \ --region <Region> \ --code-interpreter-id "<your-code-interpreter-id>" \ --session-id "<your-session-id>"
Boto3
  1. 要使用适用于 Python 的 AWS SDK 停止代码解释器会话,请使用以下stop_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" ) # Stop the Code Interpreter session response = dp_client.stop_code_interpreter_session( codeInterpreterIdentifier="aws.codeinterpreter.v1", sessionId="<your-session-id>" ) print("Session stopped successfully")
API
  1. 要使用 API 停止代码解释器会话,请使用以下调用:

    # Using awscurl awscurl -X PUT \ "https://bedrock-agentcore.<Region>.amazonaws.com/code-interpreters/aws.codeinterpreter.v1/sessions/stop?sessionId=<your-session-id>" \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ --service bedrock-agentcore \ --region <Region>