

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

# 使用 Amazon Bedrock 代理，通过基于文本的提示，在 Amazon EKS 中自动创建访问条目控制
<a name="using-amazon-bedrock-agents-to-automate-creation-of-access-entry-controls-in-amazon-eks"></a>

*Keshav Ganesh 和 Sudhanshu Saurav，Amazon Web Services*

## Summary
<a name="using-amazon-bedrock-agents-to-automate-creation-of-access-entry-controls-in-amazon-eks-summary"></a>

当多个团队需要使用共享的 Amazon Elastic Kubernetes Service（Amazon EKS）集群时，组织在管理访问控制和资源预调配方面面临着挑战。Amazon EKS 等托管式 Kubernetes 服务简化了集群操作。然而，在管理团队访问权限和资源权限方面的管理开销仍然既复杂又耗时。

此模式显示了 Amazon Bedrock 代理如何帮助您自动执行 Amazon EKS 集群访问管理。借助这一自动化，开发团队可以专注于核心应用程序开发工作，而不是处理访问控制设置和管理任务。您可以自定义 Amazon Bedrock 代理，使其通过简单的自然语言提示，对多种任务执行操作。

通过使用 AWS Lambda 功能作为操作组，Amazon Bedrock 代理可以处理诸如创建用户访问条目和管理访问策略之类的任务。此外，Amazon Bedrock 代理可以配置容器身份关联，从而允许集群中运行的 pod 访问 AWS Identity and Access Management (IAM) 资源。使用该解决方案，各个组织可以利用基于文本的简单提示来简化 Amazon EKS 集群管理、减少手动开销，并提高整体开发效率。

## 先决条件和限制
<a name="using-amazon-bedrock-agents-to-automate-creation-of-access-entry-controls-in-amazon-eks-prereqs"></a>

**先决条件**
+ 活跃 AWS 账户的.
+ 为部署过程建立了 IAM [角色和权限](https://docs.aws.amazon.com/bedrock/latest/userguide/security_iam_id-based-policy-examples.html)。这包括访问 Amazon Bedrock 基础模型 (FM)、创建 Lambda 函数以及跨目标的任何其他所需资源的权限。 AWS 账户
+ 在活跃状态 AWS 账户 下@@ [可以访问](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html)这些 Amazon Bedrock FMs：Amazon Titan Text Embeddings V2 和 Anthropic Claude 3 Haiku。
+ AWS Command Line Interface [(AWS CLI) 版本 2.9.11 或更高版本，[已安装并配置](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html)。](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)
+ [已安装](https://eksctl.io/installation/) eksctl 0.194.0 或更高版本。

**限制**
+ 可能需要提供培训和文档，以便帮助确保顺利地采用和有效地使用这些技术。使用亚马逊 Bedrock，亚马逊 EKS、Lambda、A OpenSearch mazon Service 和 [OpenAPI](https://www.openapis.org/what-is-openapi) 会给开发人员和团队带来重要的学习曲线。 DevOps 
+ 有些 AWS 服务 并非全部可用 AWS 区域。有关区域可用性，请参阅[按区域划分的 AWS 服务](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)。有关特定端点，请参阅[服务端点和配额](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)，然后选择相应服务的链接。

## 架构
<a name="using-amazon-bedrock-agents-to-automate-creation-of-access-entry-controls-in-amazon-eks-architecture"></a>

下图显示了此模式的工作流和架构组件。

![\[用于使用 Amazon Bedrock 代理，在 Amazon EKS 中创建访问控制措施的工作流和组件。\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/2c52b1ba-bbad-4a46-ab1e-10e69a0a66e7/images/c7981a86-f734-4c07-a2f7-63ad38b66ab6.png)


该解决方案将执行以下步骤：

1. 用户提交一个提示或查询，以便与 Amazon Bedrock 代理进行交互，这些提示或查询将用作输入，以供代理处理和采取行动。

1. 根据提示，Amazon Bedrock 代理会检查 OpenAPI 架构，以便确定要作为目标的正确 API。如果 Amazon Bedrock 代理找到正确的 API 调用，系统会将此请求发送到与实施这些操作的 Lambda 函数相关联的操作组。

1. 如果找不到相关的 API，Amazon Bedrock 代理会查询该 OpenSearch 馆藏。该 OpenSearch 馆藏使用索引知识库内容，这些内容来自包含 Amazon *EKS 用户指南的 Amazon* S3 存储桶。

1. 该 OpenSearch 集合将相关的上下文信息返回给 Amazon Bedrock 代理。

1. 对于可操作的请求（与 API 操作匹配的那些请求），Amazon Bedrock 代理将在虚拟私有云（VPC）内执行，并触发 Lambda 函数。

1. Lambda 函数将根据用户在 Amazon EKS 集群内的输入来执行操作。

1. 用于 Lambda 代码的 Amazon S3 存储桶存储着一个构件，其中包含为 Lambda 函数编写的代码和逻辑。

## 工具
<a name="using-amazon-bedrock-agents-to-automate-creation-of-access-entry-controls-in-amazon-eks-tools"></a>

**AWS 服务**
+ [Amazon Bedrock](https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-bedrock.html) 是一项完全托管的服务，它通过统一的 API 提供来自领先的人工智能初创公司和亚马逊的高性能基础模型 (FMs) 供您使用。
+ [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)帮助您设置 AWS 资源，快速一致地配置资源，并在和的整个 AWS 账户 生命周期中对其进行管理 AWS 区域。
+ [亚马逊 Elastic Kubernetes Service（亚马逊](https://docs.aws.amazon.com/eks/latest/userguide/getting-started.html) EKS）可帮助你在上面运行 AWS Kubernetes，而无需安装或维护自己的 Kubernetes 控制平面或节点。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 通过控制谁经过身份验证并有权使用 AWS 资源，从而帮助您安全地管理对资源的访问权限。
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) 是一项计算服务，可帮助您运行代码，无需预调配或管理服务器。它只在需要时运行您的代码，并自动进行扩展，因此您只需为使用的计算时间付费。
+ [Amazon OpenSearch ](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/what-is.html) Service 是一项托管服务，可帮助您在中部署、操作和扩展 OpenSearch 集群 AWS 云。它的集合功能可帮助您整理数据并建立全面的知识库，以供 Amazon Bedrock 代理等人工智能助手使用。
+ [Amazon Simple Storage Service（Amazon S3）](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html)是一项基于云的对象存储服务，可帮助您存储、保护和检索任意数量的数据。

**其他工具**
+ [eksctl](https://docs.aws.amazon.com/eks/latest/userguide/getting-started-eksctl.html) 是一款命令行实用程序，用于在 Amazon EKS 上创建和管理 Kubernetes 集群。

**代码存储库**

此模式的代码可在 GitHub [eks-access-controls-bedrock-agent](https://github.com/aws-samples/eks-access-controls-bedrock-agent.git) 存储库中找到。

## 最佳实践
<a name="using-amazon-bedrock-agents-to-automate-creation-of-access-entry-controls-in-amazon-eks-best-practices"></a>
+ 在实施此模式时，保持尽可能高的安全性。确保 Amazon EKS 集群是私有集群，访问权限有限，而且所有资源都位于一个虚拟私有云（VPC）内。有关详情，请参阅 Amazon EKS 文档中的[安全最佳实践](https://docs.aws.amazon.com/eks/latest/best-practices/security.html)。
+ 尽可能使用 AWS KMS [客户托管的密钥](https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html)，并向其授予有限的访问权限。
+ 遵循最低权限原则，并授予执行任务所需的最低权限。有关详情，请参阅 IAM 文档中的[授予最低权限](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#grant-least-priv)和[安全最佳实践](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)。

## 操作说明
<a name="using-amazon-bedrock-agents-to-automate-creation-of-access-entry-controls-in-amazon-eks-epics"></a>

### 设置环境
<a name="set-up-the-environment"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 克隆存储库。 | 要克隆此模式的存储库，请在您的本地工作站中运行如下命令：<pre>git clone https://github.com/aws-samples/eks-access-controls-bedrock-agent.git</pre> | AWS DevOps | 
| 获取 AWS 账户 身份证。 | 要获取 AWS 账户 ID，请按以下步骤操作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/using-amazon-bedrock-agents-to-automate-creation-of-access-entry-controls-in-amazon-eks.html)此命令将您的 AWS 账户 ID 存储在`AWS_ACCOUNT`变量中。 | AWS DevOps | 
| 为 Lambda 代码创建 S3 存储桶。 | 要实施该解决方案，您必须创建三个用于不同用途的 Amazon S3 存储桶，如[架构](#using-amazon-bedrock-agents-to-automate-creation-of-access-entry-controls-in-amazon-eks-architecture)图中所示。S3 存储桶用于存储 Lambda 代码、知识库和 OpenAPI 架构。要创建 Lambda 代码存储桶，请执行以下步骤：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/using-amazon-bedrock-agents-to-automate-creation-of-access-entry-controls-in-amazon-eks.html)package 命令创建一个包含以下内容的新 CloudFormation 模板 (`eks-access-controls-template.yaml`)：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/using-amazon-bedrock-agents-to-automate-creation-of-access-entry-controls-in-amazon-eks.html) | AWS DevOps | 
| 为知识库创建 S3 存储桶。 | 要为知识库创建 Amazon S3 存储桶，请执行以下步骤：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/using-amazon-bedrock-agents-to-automate-creation-of-access-entry-controls-in-amazon-eks.html) | AWS DevOps | 
| 为 OpenAPI 架构创建 S3 存储桶。 | 要为 OpenAPI 架构创建 Amazon S3 存储桶，请执行以下步骤：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/using-amazon-bedrock-agents-to-automate-creation-of-access-entry-controls-in-amazon-eks.html) | AWS DevOps | 

### 部署堆 CloudFormation 栈
<a name="deploy-the-cfnshort-stack"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 部署 CloudFormation 堆栈。 | 要部署 CloudFormation 堆栈，请使用之前创建`eks-access-controls-template.yaml`的 CloudFormation 模板文件。有关更多详细说明，请参阅 CloudFormation 文档[中的从 CloudFormation 控制台创建堆栈](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-console-create-stack.html)。使用 CloudFormation 模板配置 OpenSearch 索引大约需要 10 分钟。创建此堆栈之后，记下 `VPC_ID` 和 `PRIVATE_SUBNET ID`。 | AWS DevOps | 
| 创建 Amazon EKS 集群。 | 要在 VPC 内创建 Amazon EKS 集群，请执行以下步骤：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/using-amazon-bedrock-agents-to-automate-creation-of-access-entry-controls-in-amazon-eks.html)预期的结果如下所示：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/using-amazon-bedrock-agents-to-automate-creation-of-access-entry-controls-in-amazon-eks.html) | AWS DevOps | 

### 连接 Lambda 函数和 Amazon EKS 集群
<a name="connect-the-lam-function-and-the-eks-cluster"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 在 Amazon EKS 集群与 Lambda 函数之间，创建一个连接。 | 要设置网络和 IAM 权限，以便允许 Lambda 函数与 Amazon EKS 集群进行通信，请执行以下步骤：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/using-amazon-bedrock-agents-to-automate-creation-of-access-entry-controls-in-amazon-eks.html) | AWS DevOps | 

### 测试解决方案
<a name="test-the-solution"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 测试 Amazon Bedrock 代理。 | 在测试 Amazon Bedrock 代理之前，请确保执行以下操作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/using-amazon-bedrock-agents-to-automate-creation-of-access-entry-controls-in-amazon-eks.html)要访问 Amazon Bedrock 代理，请执行以下步骤：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/using-amazon-bedrock-agents-to-automate-creation-of-access-entry-controls-in-amazon-eks.html)[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/using-amazon-bedrock-agents-to-automate-creation-of-access-entry-controls-in-amazon-eks.html)您也可以要求此代理执行操作，以便建立 EKS 容器组身份关联。有关更多详细信息，请参阅 Amazon EKS 文档中的[了解 EKS 容器组身份如何向容器组（pod）授予对 AWS 服务的访问权限](https://docs.aws.amazon.com/eks/latest/userguide/pod-identities.html)。 | AWS DevOps | 

### 清理
<a name="clean-up"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 清理资源。 | 要清理此模式创建的资源，请执行如下过程。等待每个删除步骤都完成之后，再继续执行下一个步骤。此过程将永久删除这些堆栈创建的所有资源。在继续之前，请确保您已备份所有的重要数据。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/using-amazon-bedrock-agents-to-automate-creation-of-access-entry-controls-in-amazon-eks.html) | AWS DevOps | 

## 问题排查
<a name="using-amazon-bedrock-agents-to-automate-creation-of-access-entry-controls-in-amazon-eks-troubleshooting"></a>


| 问题 | 解决方案 | 
| --- | --- | 
| 在环境设置期间，返回了非零错误代码。 | 运行任何命令以便部署该解决方案时，请确认您正在使用正确的文件夹。有关详情，请参阅此模式的存储库中的 [FIRST\$1DEPLOY.md](https://github.com/aws-samples/eks-access-controls-bedrock-agent/blob/main/FIRST_DEPLOY.md) 文件。 | 
| Lambda 函数无法执行此任务。 | 请确保正确设置了从 Lambda 函数到 Amazon EKS 集群的连接。 | 
| 代理提示无法识别 APIs。 | 重新部署该解决方案。有关详情，请参阅此模式的存储库中的 [RE\$1DEPLOY.md](https://github.com/aws-samples/eks-access-controls-bedrock-agent/blob/main/RE_DEPLOY.md) 文件。 | 
| 删除此堆栈失败。 | 首次尝试删除此堆栈时，可能会失败。之所以出现这种故障，可能是因为为知识库编制索引的 OpenSearch 集合创建的自定义资源存在依赖性问题。要删除此堆栈，请保留自定义资源，以便重试此删除操作。 | 

## 相关资源
<a name="using-amazon-bedrock-agents-to-automate-creation-of-access-entry-controls-in-amazon-eks-resources"></a>

**AWS 博客**
+ [深入了解简化的 Amazon EKS 访问管理控制](https://aws.amazon.com/blogs/containers/a-deep-dive-into-simplified-amazon-eks-access-management-controls/) 

**Amazon Bedrock 文档**
+ [使用人工智能代理，在您的应用程序中自动执行任务](https://docs.aws.amazon.com/bedrock/latest/userguide/agents.html) 
+ [亚马逊 Bedrock Agents 的工作原理](https://docs.aws.amazon.com/bedrock/latest/userguide/agents-how.html)
+ [测试代理行为并对其进行故障排除](https://docs.aws.amazon.com/bedrock/latest/userguide/agents-test.html)
+ [使用操作组来定义代理要执行的操作](https://docs.aws.amazon.com/bedrock/latest/userguide/agents-action-create.html) 

**Amazon EKS 文档**
+ [了解访问控制在 Amazon EKS 中的工作原理](https://docs.aws.amazon.com/eks/latest/userguide/cluster-auth.html)