Could not connect to the endpoint URL (DynamoDB)

TL;DR — botocore 无法打开到它所解析出的 DynamoDB 端点的连接。几乎总是 --endpoint-url 错误、DynamoDB Local 未运行、一个错误/拼错的区域生成了一个不存在的主机名,或者没有网络路径(离线、VPC、安全组)。指向一个可达的端点,并确认有东西在监听。

含义

botocore.exceptions.EndpointConnectionError: Could not connect to the
endpoint URL: "http://localhost:8000/"

# what the engine actually returns, reproduced against Amazon DynamoDB (live service, us-east-1):
connect ECONNREFUSED 127.0.0.1:9

boto3/botocore 从区域(或你显式指定的 endpoint_url)构建 DynamoDB 端点 URL,然后无法与之建立 TCP/HTTP 连接。与认证或验证错误不同,请求从未到达任何正在运行的服务。它既会针对 DynamoDB Local(模拟器已关闭/端口错误)出现,也会针对真实 AWS(区域主机名错误或网络被阻断)出现。

为什么会发生

  • DynamoDB Local 未运行——你传入了 --endpoint-url http://localhost:8000,但模拟器没有在那个端口上运行(参见 connection refused)。
  • 端点 URL 错误——拼写错误、端口错误,或者在本地模拟器提供 http 服务处用了 https
  • 区域错误——一个拼错的区域(us-east-11)解析到一个不存在的主机名,因此无法建立连接。
  • 没有网络路径——离线,或者 DynamoDB 流量被 VPC 端点、安全组或网络 ACL 阻断。
  • 跨容器/跨主机——在 Docker 内部,localhost 是容器自身,而不是主机或 DynamoDB Local 服务。

如何修复

  1. 确认端点处有什么在监听:
    curl http://localhost:8000    # DynamoDB Local answers with a small response
  2. 修正端点 URL——正确的主机、端口(默认 8000)和协议(Local 用 http)。
  3. 检查真实 AWS 的区域拼写,并确保你有一条网络路由(VPC 端点/安全组规则允许 DynamoDB)。
  4. 在 Docker 中,使用 compose 服务名或 host.docker.internal 而不是 localhosthost.docker.internal 在 Docker Desktop 中自动解析;在 Linux Docker Engine 上添加 --add-host host.docker.internal:host-gateway)。
  5. 在与真实 AWS 对话? 完全去掉 --endpoint-url 覆盖,让 botocore 构建正确的区域端点。

将 DynoTable 指向 Local

DynoTable 验证每个配置文件上的 Test Connection 的连接 Settings → Profiles (Connect an AWS account)。对于 DynamoDB本地,设置端点http://localhost:8000(或:4566对于LocalStack)使用占位符凭据 — CLI 需要的值相同。按⌘P 当你的应用程序使用与 DynoTable 不同的端口时切换配置文件。指南: Connect to DynamoDB Local & LocalStack。与真实的 AWS 相比,区域字符串中的拼写错误会生成不正确的主机名解析 — 与无法访问的本地端口相同的 EndpointConnectionError 形状。调试前在配置文件上按aws sts get-caller-identity确认 DynamoDB特定设置。

相关错误

来源

无需控制台即可使用 DynamoDB

一款快速的 DynamoDB 桌面客户端,可运行 DynamoDB 无法执行的真正 SQL——JOINs、GROUP BY、聚合——并支持可视化编辑和运行在你自己的 Bedrock 密钥上的 AI agent。

30 天免费试用,无需信用卡 — 之后为无时间限制的免费版。