> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-docs-zh.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# AWS lambda 集成的 Agent

> 使用 LangChain JavaScript 集成 Agent with AWS lambda 工具。

完整文档请参阅：[https://docs.aws.amazon.com/lambda/index.html](https://docs.aws.amazon.com/lambda/index.html)

**AWS Lambda** 是由亚马逊网络服务（AWS）提供的无服务器计算服务，旨在允许开发者无需配置或管理服务器即可构建和运行应用程序和服务。这种无服务器架构使您能够专注于编写和部署代码，而 AWS 将自动处理运行您的应用程序所需的扩展、补丁和管理基础设施。

通过将 AWSLambda 包含在提供给智能体的工具列表中，您可以赋予智能体调用运行在您的 AWS 云中的代码的能力，以满足您的任何需求。

当智能体使用 AWSLambda 工具时，它将提供一个类型为 `string` 的参数，该参数随后将通过 `event` 参数传递给 Lambda 函数。

本快速入门将演示智能体如何使用 Lambda 函数通过 [Amazon Simple Email Service](https://aws.amazon.com/ses/) 发送电子邮件。发送电子邮件的 lambda 代码并未提供，但如果您想了解如何完成此操作，请参阅 [如何使用 Lambda 和 SES 发送电子邮件](https://repost.aws/knowledge-center/lambda-send-email-ses)。请注意，这是一个故意简单的示例；Lambda 可以用于执行近乎无限的其他目的（包括执行更多 Langchains）！

### 关于凭证的说明：

* 如果您尚未通过 AWS CLI 运行 [`aws configure`](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)，则必须将 `region`、`accessKeyId` 和 `secretAccessKey` 提供给 AWSLambda 构造函数。
* 与这些凭证对应的 IAM 角色必须具有调用 Lambda 函数的权限。

> [!TIP]
>
> 请参阅 [有关安装 LangChain 包的一般说明的此部分](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/install.md)。

```bash npm theme={null}
npm install @langchain/openai @langchain/core
```

```typescript theme={null}
import { OpenAI } from "@langchain/openai";
import { SerpAPI } from "@langchain/classic/tools";
import { AWSLambda } from "@langchain/classic/tools/aws_lambda";
import { initializeAgentExecutorWithOptions } from "@langchain/classic/agents";

const model = new OpenAI({ temperature: 0 });
const emailSenderTool = new AWSLambda({
  name: "email-sender",
  // tell the Agent precisely what the tool does
  description:
    "Sends an email with the specified content to testing123@gmail.com",
  region: "us-east-1", // optional: AWS region in which the function is deployed
  accessKeyId: "abc123", // optional: access key id for an IAM user with invoke permissions
  secretAccessKey: "xyz456", // optional: secret access key for that IAM user
  functionName: "SendEmailViaSES", // the function name as seen in AWS Console
});
const tools = [emailSenderTool, new SerpAPI("api_key_goes_here")];
const executor = await initializeAgentExecutorWithOptions(tools, model, {
  agentType: "zero-shot-react-description",
});

const input = `Find out the capital of Croatia. Once you have it, email the answer to testing123@gmail.com.`;
const result = await executor.invoke({ input });
console.log(result);
```

## 相关

* 工具 [概念指南](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/tools.md)
* 工具 [操作指南](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/tools.md)

***

> 官方原文：[src/oss/javascript/integrations/tools/lambda\_agent.mdx](https://github.com/langchain-ai/docs/blob/main/src/oss/javascript/integrations/tools/lambda_agent.mdx) · 非官方翻译，译文由 AI 生成，以英文原文为准。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.