AWS 终于构建了它自己的 AWS 模拟器
AWS emulator

原始链接: https://github.com/aws/aws-emulator

AWS Emulator 是用于在无 AWS 账户或真实 AWS 资源时构建和测试软件的本地免费 AWS API 模拟器。它在本地提供 HTTPS 端点;可通过环境变量将 AWS CLI 或 SDK 指向它,或在 Rust 测试中内嵌运行。需要 AWS CLI 2.35.0+。它不适用于生产或安全测试。遥测默认开启且数据最小化;可通过 `--telemetry off`、`EMULATOR_TELEMETRY`、`config.toml` 或内嵌选项禁用。从源码构建需要 Rust/Cargo、C 编译器、约 100 GB 磁盘空间和多核 CPU。许可证为 CC0-1.0,供应商代码除外,后者为 Apache 2.0。

Hacker News 讨论了 AWS 新的官方 aws-emulator,一个用 Rust 编写的本地 AWS API 模拟器。AWS 表示它是真实、持续维护的产品。用户就其 AI 生成代码、维护前景和完成度展开了讨论。兼容性不一:共享表格显示热门服务的通过率大多在 40%–77%,其中 CloudFormation、EC2、IAM、Lambda、RDS 等较低;部分服务和边缘情况不受支持。安全功能明确受限:IAM 策略、资源策略、KMS、跨账户/区域以及其他安全控制未被真实模拟。评论者将其与 LocalStack、Floci、MiniStack、FakeCloud 和 moto 比较;部分人在 LocalStack 定价变化后欢迎第一方替代品,而另一些人不信任 AI 生成、快速提交的代码。构建要求较高(约 100GB),且默认开启遥测。总体而言,该模拟器适合本地集成测试,但不能完全替代真实 AWS。
相关文章

原文

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.

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

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

Server mode (CLI and any SDK)

Point your SDK at a running emulator by setting environment variables. See Pointing your AWS SDK at 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.

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/.

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.

  • 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 build -p aws-emulator-router
cargo run   -p aws-emulator-router

The emulator serves HTTPS on 127.0.0.1:9297 (self-signed certificate).

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.toml              # workspace: one member per service, plus the core crates
├── services/
│   └── service-<name>/     # ONE CRATE PER SERVICE
│       ├── smithy-model/   # <name>.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

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. 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

To turn telemetry off for every run on a machine, add these lines to the emulator settings file, config.toml. The file is ~/.aws/emulator/config.toml on Linux and macOS, and %USERPROFILE%\.aws\emulator\config.toml on Windows. To use a different file, set the EMULATOR_CONFIG environment variable to its path.

[telemetry]
enabled = false

Use the embedded configuration API

In embedded mode, turn off telemetry in the options that you pass when you create the emulator.

use aws_emulator_embedded::{AwsEmulatorEmbedded, EmbeddedOptions, Telemetry};

fn main() {
    let emulator = AwsEmulatorEmbedded::new(EmbeddedOptions::default().telemetry(Telemetry::Off));
    let _http_client = emulator.http_client();
}

You might build a tool that includes the emulator, such as a test framework that other people run. If you do, tell your users about telemetry and give them a way to turn it off. You can also ship your tool with telemetry off.

Reporting issues and contributing

Report bugs and fidelity gaps in GitHub Issues. The most useful report names the service, the operation, your SDK and version, the request you sent, and how the response differed from real AWS. This repository does not take PRs.

This software is licensed under the CC0 1.0 Universal (CC0-1.0) License, except the code in the vendor/ directory, which is under the Apache License 2.0. See LICENSE for details, and vendor/README.md for the license of the code in vendor/.

联系我们 contact @ memedata.com