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

# AWS Lambda 集成

> 使用 LangChain Python 与 AWS Lambda 工具集成。

> [`Amazon AWS Lambda`](https://aws.amazon.com/pm/lambda/) 是由 `Amazon Web Services` (`AWS`) 提供的无服务器计算服务。它帮助开发者构建和运行应用程序与服务，无需配置或管理服务器。这种无服务器架构使您能够专注于编写和部署代码，而 AWS 自动负责扩展、修补和管理运行应用程序所需的基础设施。

本笔记本介绍如何使用 `AWS Lambda` 工具。

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

当 Agent 使用 `AWS Lambda` 工具时，它将提供一个字符串类型的参数，该参数将通过 event 参数传递给 Lambda 函数。

首先，您需要安装 `boto3` Python 包。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install -qU boto3 > /dev/null
pip install -qU langchain-community
```

为了使 Agent 能够使用该工具，您必须为其提供与 Lambda 函数逻辑功能相匹配的名称和描述。

您还必须提供函数的名称。

请注意，由于此工具实际上只是 boto3 库的一个包装器，您需要运行 `aws configure` 才能使用该工具。更多详情，请参阅 [AWS CLI 文档](https://docs.aws.amazon.com/cli/index.html)。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain.agents import create_agent, load_tools
from langchain_openai import OpenAI

llm = OpenAI(temperature=0)

tools = load_tools(
    ["awslambda"],
    awslambda_tool_name="email-sender",
    awslambda_tool_description="sends an email with the specified content to test@testing123.com",
    function_name="testFunction1",
)

agent = create_agent(
    model=llm,
    tools=tools,
)

agent.invoke("Send an email to test@testing123.com saying hello world.")
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
```

***

<div className="source-links">
  <Callout icon="terminal-2">
    [将这些文档连接](/use-these-docs)到 Claude、VSCode 等，通过 MCP 获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/tools/awslambda.mdx) 或 [提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
