AWS emulator

本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。

AWS emulator

AWS Emulator README AWS Emulator is a local emulator of the AWS APIs. You use it to test your software without calling AWS, on your own machine, on a development server, or in continuous integration (CI). You don’t need an AWS account. Your requests go to the emulator, not to AWS. So you work with emulated resources instead of AWS resources. AWS Emulator has no additional service fee. You pay only for AWS resources when you deploy on AWS.

AWS Emulator README AWS Emulator 是 AWS API 的本地模拟器。您可以使用它在自己的机器、开发服务器或持续集成 (CI) 环境中测试软件,而无需调用 AWS。您不需要 AWS 账户。您的请求会发送到模拟器,而不是 AWS。因此,您使用的是模拟资源,而不是 AWS 资源。AWS Emulator 没有额外的服务费用。您仅在部署到 AWS 时才需要为 AWS 资源付费。

The emulator is a local program that serves an AWS API endpoint. It has no graphical interface. After you start the emulator, you set environment variables to point the AWS CLI or an AWS SDK at its endpoint. Then you run your code as usual. In embedded mode, you pass the emulator’s HTTP client to your SDK instead. AWS Emulator is for building and testing. Don’t use it for production workloads or to test security. See Security in AWS Emulator. Documentation: AWS Emulator User Guide

该模拟器是一个提供 AWS API 端点的本地程序。它没有图形界面。启动模拟器后,您需要设置环境变量,将 AWS CLI 或 AWS SDK 指向其端点。然后像往常一样运行代码。在嵌入式模式下,您可以将模拟器的 HTTP 客户端传递给 SDK。AWS Emulator 仅用于构建和测试。请勿将其用于生产工作负载或进行安全测试。请参阅 AWS Emulator 中的安全性。文档:AWS Emulator 用户指南。

Quick start With an AI coding agent Install the aws-emulator skill, then ask your agent to set up the emulator. This needs the AWS CLI version 2.35.0 or later. See Getting started with an AI coding agent. aws agent-toolkit add-skill —skill-name aws-emulator —region us-east-1

快速入门:使用 AI 编码代理。安装 aws-emulator 技能,然后要求您的代理设置模拟器。这需要 AWS CLI 2.35.0 或更高版本。请参阅“AI 编码代理入门”。aws agent-toolkit add-skill —skill-name aws-emulator —region us-east-1

Server mode (CLI and any SDK) Linux: install the RPM or Debian package and run aws-emulator. See Getting started on Linux. Windows / macOS: run the emulator in a container built from a short Dockerfile. See Getting started with Docker. Point your SDK at a running emulator by setting environment variables. See Pointing your AWS SDK at AWS Emulator.

服务器模式(CLI 和任何 SDK):Linux:安装 RPM 或 Debian 软件包并运行 aws-emulator。请参阅“Linux 入门”。Windows / macOS:在从简短 Dockerfile 构建的容器中运行模拟器。请参阅“Docker 入门”。通过设置环境变量将您的 SDK 指向正在运行的模拟器。请参阅“将您的 AWS SDK 指向 AWS Emulator”。

Embedded mode (Rust tests) Add the emulator as a dev-dependency and run it in-process, one isolated instance per test. There is no endpoint URL, certificate, or environment variable to set. Your test wires the emulator’s HTTP client straight into the SDK client. See Getting started with embedded mode, and Building from source below for its build cost.

嵌入式模式(Rust 测试):将模拟器添加为开发依赖项并在进程内运行,每个测试对应一个隔离实例。无需设置端点 URL、证书或环境变量。您的测试将模拟器的 HTTP 客户端直接连接到 SDK 客户端。请参阅“嵌入式模式入门”,以及下方的“从源代码构建”以了解其构建成本。

Known issues To see how closely each service matches AWS, check the fidelity scores published with each release on the releases page. To check whether your own project is expected to work, see Checking whether your project works with AWS Emulator. Individual gaps are tracked in the repository’s issues/ directory. APIs and behaviors that don’t work yet are under issues/things-that-do-not-work/, and ones that have since been fixed move to issues/things-that-now-work/.

已知问题:要查看每项服务与 AWS 的匹配程度,请查看发布页面上随每个版本发布的保真度分数。要检查您自己的项目是否预期可以运行,请参阅“检查您的项目是否适用于 AWS Emulator”。个别差距在存储库的 issues/ 目录中进行跟踪。尚未实现的功能和行为位于 issues/things-that-do-not-work/ 下,已修复的功能则会移至 issues/things-that-now-work/。

Building from source You need this if you are modifying the emulator, running it from a checkout, or using embedded mode. Embedded mode compiles the emulator into your test binary, so the prerequisites and build-cost guidance below apply to it too. Most other users install a prebuilt package instead (see Quick start). Building from source is supported on Linux (x86_64 and aarch64); on Windows and macOS, use the Docker path above.

从源代码构建:如果您正在修改模拟器、从检出版本运行它或使用嵌入式模式,则需要此操作。嵌入式模式会将模拟器编译到您的测试二进制文件中,因此下方的先决条件和构建成本指南也适用于它。大多数其他用户应安装预构建的软件包(请参阅“快速入门”)。Linux (x86_64 和 aarch64) 支持从源代码构建;在 Windows 和 macOS 上,请使用上述 Docker 路径。

Prerequisites A Rust toolchain with Cargo (install via rustup). A C compiler, such as GCC or clang. Some dependencies build C code. At least 100 GB of free disk for target/. The workspace has one crate per AWS service, so a debug build of everything is large, and it grows as services are added. A multi-core machine. A cold full build compiles every service crate, so the first build takes a while; fewer cores take proportionally longer. After that, rebuilding after a change to one service is much faster.

先决条件:带有 Cargo 的 Rust 工具链(通过 rustup 安装)。C 编译器,例如 GCC 或 clang。某些依赖项会构建 C 代码。至少 100 GB 的可用磁盘空间用于 target/。工作区中每个 AWS 服务对应一个 crate,因此所有内容的调试构建都很大,并且会随着服务的添加而增长。多核机器。冷全量构建会编译每个服务 crate,因此首次构建需要一些时间;核心数越少,耗时越长。此后,在更改一项服务后重新构建的速度会快得多。

Build and run cargo build -p aws-emulator-router cargo run -p aws-emulator-router The emulator serves HTTPS on 127.0.0.1:9297 (self-signed certificate).

构建并运行:cargo build -p aws-emulator-router cargo run -p aws-emulator-router。模拟器在 127.0.0.1:9297 上提供 HTTPS 服务(自签名证书)。

Embedded mode build cost Embedded mode compiles the emulator into your test binary, so your project’s first cargo test builds the emulator’s service crates alongside your own code. Budget a first build and target/ on the same order as building from source above, then fast incremental builds. Recommendation: reuse one CARGO_TARGET_DIR across projects, cache target/ (or use sccache) in CI, and pin the emulator to a release commit so it isn’t rebuilt on every change.

嵌入式模式构建成本:嵌入式模式会将模拟器编译到您的测试二进制文件中,因此您项目的首次 cargo test 会在构建您自己的代码的同时构建模拟器的服务 crate。首次构建和 target/ 的预算与上述从源代码构建的规模相当,之后是快速的增量构建。建议:在项目间重用一个 CARGO_TARGET_DIR,在 CI 中缓存 target/(或使用 sccache),并将模拟器固定到某个发布提交,这样就不会在每次更改时都重新构建。

Repository layout . ├── Cargo.toml # workspace: one member per service, plus the core crates ├── services/ │ └── service-/ # ONE CRATE PER SERVICE │ ├── smithy-model/ # .json — the Smithy model that drives the wire protocol │ ├── build.rs # generates the service declaration from the model │ ├── src/ │ │ ├── service.rs # request routing and refusal overrides │ │ ├── state.rs # this service’s in-memory state │ │ └── ops/ # one file per operation │ └── tests/ ├── core/ │ ├── router/ # the emulator binary: mounts every service on one endpoint │ └── embedded/ # the in-process (embedded mode) facade ├── vendor/ # framework crates — do not edit (replaced on update) └── issues/ # tracked fidelity issues

存储库布局:. ├── Cargo.toml # 工作区:每个服务一个成员,加上核心 crate ├── services/ │ └── service-/ # 每个服务一个 CRATE │ ├── smithy-model/ # .json — 驱动线路协议的 Smithy 模型 │ ├── build.rs # 从模型生成服务声明 │ ├── src/ │ │ ├── service.rs # 请求路由和拒绝覆盖 │ │ ├── state.rs # 此服务的内存状态 │ │ └── ops/ # 每个操作一个文件 │ └── tests/ ├── core/ │ ├── router/ # 模拟器二进制文件:将每个服务挂载到一个端点上 │ └── embedded/ # 进程内(嵌入式模式)外观 ├── vendor/ # 框架 crate — 请勿编辑(更新时会被替换) └── issues/ # 跟踪的保真度问题

Telemetry AWS Emulator is configured to collect and report usage data to AWS, to gain insight into how AWS Emulator is used. Telemetry is on by default. AWS Emulator collects telemetry data with strict data minimization in mind, preventing identification or attribution to specific users, accounts, or organizations. Its records never include what’s in your requests or responses, your code, your credentials, or personal data. We don’t share telemetry with third parties. For details on what is collected and how the data is handled, see Telemetry in AWS Emulator.

遥测:AWS Emulator 配置为向 AWS 收集和报告使用数据,以深入了解 AWS Emulator 的使用方式。遥测功能默认开启。AWS Emulator 在收集遥测数据时严格遵循数据最小化原则,防止识别或归因于特定用户、账户或组织。其记录绝不包含您的请求或响应内容、代码、凭据或个人数据。我们不会与第三方共享遥测数据。有关收集内容及数据处理方式的详细信息,请参阅 AWS Emulator 中的“遥测”。

To turn telemetry off, use one of the following options. Use a command-line option Start the emulator with the —telemetry option (short form -t) set to off. This setting applies only to that emulator process. aws-emulator —telemetry off In a container, add —telemetry off after the image name in the docker run command. Use an environment variable Set EMULATOR_TELEMETRY to off before you start the emulator. This setting applies to every emulator that you start from that shell. EMULATOR_TELEMETRY accepts on, true, or 1 to turn telemetry on, and off, false, or 0 to turn it off. Values aren’t case sensitive. Any other value turns telemetry off, and the startup notice shows a warning. export EMULATOR_TELEMETRY=off aws-emulator

要关闭遥测,请使用以下选项之一。使用命令行选项:启动模拟器时将 —telemetry 选项(简写为 -t)设置为 off。此设置仅适用于该模拟器进程。aws-emulator —telemetry off。在容器中,在 docker run 命令的镜像名称后添加 —telemetry off。使用环境变量:在启动模拟器之前将 EMULATOR_TELEMETRY 设置为 off。此设置适用于您从该 shell 启动的每个模拟器。EMULATOR_TELEMETRY 接受 on、true 或 1 来开启遥测,接受 off、false 或 0 来关闭它。值不区分大小写。任何其他值都会关闭遥测,启动通知会显示警告。export EMULATOR_TELEMETRY=off aws-emulator。