npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@steadybit/failure-lambda

v0.6.0

Published

Module for failure injection into AWS Lambda

Downloads

12

Readme

Failure injection for AWS Lambda - failure-lambda

Description | How to with SSM Parameter | How to with AppConfig | Usage | Examples | Notes | Changelog

Description

@steadybit/failure-lambda is a small Node module for injecting failure into AWS Lambda (https://aws.amazon.com/lambda). It offers a simple failure injection wrapper for your Lambda handler where you then can choose to inject failure by setting the failureMode to latency, exception, denylist, diskspace or statuscode. You control your failure injection using SSM Parameter Store or AWS AppConfig.

How to install with parameter in SSM Parameter Store

  1. Install @steadybit/failure-lambda module using NPM.
npm install @steadybit/failure-lambda
  1. Add the module to your Lambda function code.
const failureLambda = require("@steadybit/failure-lambda");
  1. Wrap your handler.
exports.handler = failureLambda(async (event, context) => {
  ...
})
  1. Create a parameter in SSM Parameter Store.
{
  "isEnabled": false,
  "failureMode": "latency",
  "rate": 1,
  "minLatency": 100,
  "maxLatency": 400,
  "exceptionMsg": "Exception message!",
  "statusCode": 404,
  "diskSpace": 100,
  "denylist": ["s3.*.amazonaws.com", "dynamodb.*.amazonaws.com"]
}
aws ssm put-parameter --region eu-west-1 --name failureLambdaConfig --type String --overwrite --value "{\"isEnabled\": false, \"failureMode\": \"latency\", \"rate\": 1, \"minLatency\": 100, \"maxLatency\": 400, \"exceptionMsg\": \"Exception message!\", \"statusCode\": 404, \"diskSpace\": 100, \"denylist\": [\"s3.*.amazonaws.com\", \"dynamodb.*.amazonaws.com\"]}"
  1. Add an environment variable to your Lambda function with the key FAILURE_INJECTION_PARAM and the value set to the name of your parameter in SSM Parameter Store.
  2. Add permissions to the parameter for your Lambda function.
  3. Try it out!

How to install with hosted configuration in AWS AppConfig

  1. Install @steadybit/failure-lambda module using NPM.
npm install @steadybit/failure-lambda
  1. Add the module to your Lambda function code.
const failureLambda = require("@steadybit/failure-lambda");
  1. Wrap your handler.
exports.handler = failureLambda(async (event, context) => {
  ...
})
  1. Create Application, Environment, Configuration Profile, and Hosted Configuration in AppConfig console.
  2. Deploy a version of the configuration.
  3. Add the AWS AppConfig layer for Lambda extensions to your Lambda function. See details.
  4. Add environment variables to your Lambda function.
FAILURE_APPCONFIG_APPLICATION: YOUR APPCONFIG APPLICATION
FAILURE_APPCONFIG_ENVIRONMENT: YOUR APPCONFIG ENVIRONMENT
FAILURE_APPCONFIG_CONFIGURATION: YOUR APPCONFIG CONFIGURATION PROFILE
  1. Add permissions to the AppConfig Application, Environment, and Configuration Profile for your Lambda function.
  2. Try it out!

Usage

Edit the values of your parameter in SSM Parameter Store or hosted configuration in AWS AppConfig to use the failure injection module.

  • isEnabled: true means that failure is injected into your Lambda function.
  • isEnabled: false means that the failure injection module is disabled and no failure is injected.
  • failureMode selects which failure you want to inject. The options are latency, exception, denylist, diskspace or statuscode as explained below.
  • rate controls the rate of failure. 1 means that failure is injected on all invocations and 0.5 that failure is injected on about half of all invocations.
  • minLatency and maxLatency is the span of latency in milliseconds injected into your function when failureMode is set to latency.
  • exceptionMsg is the message thrown with the exception created when failureMode is set to exception.
  • statusCode is the status code returned by your function when failureMode is set to statuscode.
  • diskSpace is size in MB of the file created in tmp when failureMode is set to diskspace.
  • denylist is an array of regular expressions, if a connection is made to a host matching one of the regular expressions it will be blocked.

Examples

In the subfolder example is a sample application which will install an AWS Lambda function, an Amazon DynamoDB table, and a parameter in SSM Parameter Store. You can install it using AWS SAM, AWS CDK, or Serverless Framework.

AWS SAM

cd example/sam
npm install
sam build
sam deploy --guided

AWS CDK

cd example/cdk
npm install
cdk deploy

Serverless Framework

cd example/sls
npm install
sls deploy

Notes

This module is a fork of Gunnar Grosch's failure-lambda.

Inspired by Yan Cui's articles on latency injection for AWS Lambda (https://hackernoon.com/chaos-engineering-and-aws-lambda-latency-injection-ddeb4ff8d983) and Adrian Hornsby's chaos injection library for Python (https://github.com/adhorn/aws-lambda-chaos-injection/).