Rust SDK

Install and use the fakecloud SDK for Rust tests.

Install

cargo add fakecloud-sdk

Rust 1.75+.

Initialize

use fakecloud_sdk::FakeCloudClient;

let fc = FakeCloudClient::new("http://localhost:4566");
// or default:
let fc = FakeCloudClient::default();

Top-level

MethodDescription
health().awaitServer health check
reset().awaitReset all service state
reset_service(service).awaitReset a single service

fc.bedrock()

MethodDescription
get_invocations().awaitList runtime invocations
set_model_response(model_id, text).awaitSingle canned response
set_response_rules(model_id, rules).awaitPrompt-conditional rules
clear_response_rules(model_id).awaitClear rules for a model
queue_fault(rule).awaitQueue a fault rule
get_faults().awaitList queued fault rules
clear_faults().awaitClear all queued fault rules

fc.lambda(), fc.ses(), fc.sns(), fc.sqs(), fc.events(), fc.s3(), fc.dynamodb(), fc.secretsmanager(), fc.cognito(), fc.stepfunctions(), fc.rds(), fc.apigatewayv2()

Each service accessor mirrors the TypeScript SDK's surface with Rust method naming (get_messages, tick_ttl, fire_rule, etc.). See the TypeScript reference for the full method list.

The authoritative per-method list for Rust lives in the fakecloud-sdk crate source.

Error handling

All methods return Result<T, FakeCloudError>:

use fakecloud_sdk::FakeCloudError;

match fc.cognito().confirm_user("pool-1", "nobody").await {
    Ok(_) => {}
    Err(FakeCloudError::Http { status, body }) => {
        println!("status {}, body {}", status, body);
    }
    Err(e) => eprintln!("{}", e),
}

Example: end-to-end test

use aws_sdk_sqs::Client;
use aws_config::BehaviorVersion;
use fakecloud_sdk::FakeCloudClient;

#[tokio::test]
async fn app_publishes_to_sqs() {
    let fc = FakeCloudClient::default();
    fc.reset().await.unwrap();

    let config = aws_config::defaults(BehaviorVersion::latest())
        .endpoint_url("http://localhost:4566")
        .region("us-east-1")
        .load()
        .await;
    let sqs = Client::new(&config);

    sqs.send_message()
        .queue_url("http://localhost:4566/000000000000/my-queue")
        .message_body("hello")
        .send()
        .await
        .unwrap();

    let messages = fc.sqs().get_messages().await.unwrap();
    assert_eq!(messages.len(), 1);
    assert_eq!(messages[0].body, "hello");
}

Source