

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

# 创建和管理工作负载身份
<a name="creating-agent-identities"></a>

根据您的工作流程和集成要求，您可以使用多种方法创建代理身份，包括 Amazon CLI 和 AgentCore SDK。 AgentCore Identity 为身份创建提供了多个接口，包括用于自动化和脚本编写的命令行工具以及用于与现有系统集成的编程 API。每种创建方法都支持全方位的身份属性，同时为不同的用例和用户偏好提供适当的接口。

**Topics**
+ [使用管理身份 Amazon CLI](#cli-creation)
+ [使用 AgentCore SDK 创建身份](#sdk-creation)

## 使用管理身份 Amazon CLI
<a name="cli-creation"></a>

C Amazon LI 提供了一种创建和删除代理身份的直接方法。

 **创建身份 ** 

以下命令创建名为的工作负载标识{{my-agent}}。

```
aws bedrock-agentcore-control create-workload-identity \
    --name "my-agent"
```

 **列出所有身份 ** 

以下命令列出了您账户中的所有工作负载身份。

```
aws bedrock-agentcore-control list-workload-identities
```

 **删除身份** 

以下命令删除名为的工作负载标识{{my-agent}}。

```
aws bedrock-agentcore-control delete-workload-identity \
    --name "my-agent"
```

## 使用 AgentCore SDK 创建身份
<a name="sdk-creation"></a>

该 AgentCore 软件开发工具包支持在 Python 中创建工作负载身份。

 **Python 示 ** 

以下 Python 代码使用 AgentCore SDK 创建工作负载身份。

```
from bedrock_agentcore.services.identity import IdentityClient

# Initialize the client
identity_client = IdentityClient("us-east-1")

# Create a new workload identity for agent
response = identity_client.create_workload_identity(name='my-python-agent')
agentArn = response['workloadIdentityArn']

print(f"Created agent identity with ARN: {agentArn}")
```