

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 停止 AgentCore 代码解释器会话
<a name="code-interpreter-stop-session"></a>

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

**Example**  

1. 要使用 Amazon 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>"
   ```

1. 要使用 Amazon 适用于 Python 的软件开发工具包停止代码解释器会话，请使用以下`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")
   ```

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>
   ```