UNPKG

failure-lambda

Version:

Failure injection for AWS Lambda - chaos engineering made simple

47 lines (42 loc) 2.51 kB
import { F as FailureFlagsConfig, R as ResolvedFailure, C as ConfigValidationError, M as MatchCondition, L as LambdaHandler, a as FailureLambdaOptions } from './types-B8Ty8jhf.js'; export { b as FailureMode, c as FlagValue, d as MatchOperator } from './types-B8Ty8jhf.js'; import 'aws-lambda'; /** Validate a single flag value. Returns array of errors (empty = valid). */ declare function validateFlagValue(mode: string, raw: Record<string, unknown>): ConfigValidationError[]; /** Parse raw JSON into FailureFlagsConfig. Validates each known flag key. */ declare function parseFlags(raw: Record<string, unknown>): FailureFlagsConfig; /** * Resolve enabled flags into an ordered array of failures to inject. * Order: latency, diskspace, denylist (non-terminating), then statuscode, exception (terminating). * Defaults percentage to 100 when omitted. */ declare function resolveFailures(config: FailureFlagsConfig): ResolvedFailure[]; /** Fetch config from AppConfig or SSM, with caching. */ declare function getConfig(): Promise<FailureFlagsConfig>; /** Clear the config cache. Useful for testing. @internal */ declare function clearConfigCache(): void; /** Resolve a dot-separated path against a nested object */ declare function getNestedValue(obj: unknown, path: string): unknown; /** Check whether all match conditions are satisfied by the event */ declare function matchesConditions(event: unknown, conditions: MatchCondition[]): boolean; /** * Wraps a Lambda handler with failure injection. * * Each failure mode is an independent feature flag. Multiple failures can * be active simultaneously. Pre-handler modes run before the handler * (latency, timeout, diskspace, denylist, statuscode, exception). * Post-handler modes (corruption) run after the handler returns. * * Flags with `match` conditions only fire when the event satisfies all conditions. * * @example * ```ts * import failureLambda from "failure-lambda"; * * export const handler = failureLambda(async (event, context) => { * // your handler logic * }); * ``` */ declare function injectFailure<TEvent = unknown, TResult = unknown>(handler: LambdaHandler<TEvent, TResult>, options?: FailureLambdaOptions): LambdaHandler<TEvent, TResult>; export { ConfigValidationError, FailureFlagsConfig, FailureLambdaOptions, LambdaHandler, MatchCondition, ResolvedFailure, clearConfigCache, injectFailure as default, getConfig, getNestedValue, injectFailure, matchesConditions, parseFlags, resolveFailures, validateFlagValue };