TypeScript SDK

Install and use the fakecloud SDK for TypeScript and JavaScript tests.

Install

npm install fakecloud

Works in Node.js and any environment with fetch. TypeScript types are bundled.

Initialize

import { FakeCloud } from "fakecloud";

const fc = new FakeCloud(); // defaults to http://localhost:4566
// or
const fc = new FakeCloud("http://localhost:5000");

Top-level

MethodDescription
health()Server health check
reset()Reset all service state
resetService(service)Reset a single service

fc.bedrock

MethodDescription
getInvocations()List recorded Bedrock runtime invocations (each has error field)
setModelResponse(modelId, text)Configure a single canned response for a model
setResponseRules(modelId, rules)Replace prompt-conditional response rules for a model
clearResponseRules(modelId)Clear all prompt-conditional response rules for a model
queueFault(rule)Queue a fault rule (e.g. ThrottlingException) for the next N calls
getFaults()List currently queued fault rules
clearFaults()Clear all queued fault rules

fc.lambda

MethodDescription
getInvocations()List recorded Lambda invocations
getWarmContainers()List warm (cached) Lambda containers
evictContainer(functionName)Evict a warm container

fc.ses

MethodDescription
getEmails()List all sent emails
simulateInbound(req)Simulate an inbound email (receipt rules)

fc.sns

MethodDescription
getMessages()List all published messages
getPendingConfirmations()List subscriptions pending confirmation
confirmSubscription(req)Confirm a pending subscription

fc.sqs

MethodDescription
getMessages()List all messages across all queues
tickExpiration()Tick the message expiration processor
forceDlq(queueName)Force all messages to the queue's DLQ

fc.events

MethodDescription
getHistory()Get event history and delivery records
fireRule(req)Fire an EventBridge rule manually

fc.s3

MethodDescription
getNotifications()List S3 notification events
tickLifecycle()Tick the lifecycle processor

fc.dynamodb

MethodDescription
tickTtl()Tick the TTL processor

fc.secretsmanager

MethodDescription
tickRotation()Tick the rotation scheduler

fc.cognito

MethodDescription
getConfirmationCodes()List all pending confirmation codes
getConfirmationCodesForUser(poolId, username)Codes for a specific user
confirmUser(req)Force-confirm a user
getTokens()List active tokens
expireTokens(req)Expire tokens for a pool/user
getAuthEvents()List auth events

fc.stepfunctions

MethodDescription
getExecutions()List all executions

fc.rds

MethodDescription
getInstances()List managed RDS instances

fc.apigatewayv2

MethodDescription
getRequests()List recorded HTTP API requests

Error handling

All methods throw FakeCloudError on non-2xx responses:

import { FakeCloudError } from "fakecloud";

try {
  await fc.cognito.confirmUser({ userPoolId: "pool-1", username: "nobody" });
} catch (err) {
  if (err instanceof FakeCloudError) {
    console.log(err.status); // 404
    console.log(err.body);   // error body from fakecloud
  }
}

Example: full test loop

import { FakeCloud } from "fakecloud";
import { SQSClient, SendMessageCommand } from "@aws-sdk/client-sqs";

const fc = new FakeCloud();
const sqs = new SQSClient({
  endpoint: "http://localhost:4566",
  region: "us-east-1",
  credentials: { accessKeyId: "test", secretAccessKey: "test" },
});

beforeEach(() => fc.reset());

test("app publishes to SQS", async () => {
  await sqs.send(new SendMessageCommand({
    QueueUrl: "http://localhost:4566/000000000000/my-queue",
    MessageBody: "hello",
  }));

  const { messages } = await fc.sqs.getMessages();
  expect(messages).toHaveLength(1);
  expect(messages[0].body).toBe("hello");
});

Source