Skip to content

Commit 17d85b0

Browse files
committed
Modified to only include the exception fix for now
1 parent a3f5de0 commit 17d85b0

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ exports.handler = failureLambda(async (event, context) => {
2222
```
2323
4. Create a parameter in SSM Parameter Store.
2424
```json
25-
{"isEnabled": false, "failureMode": "latency", "rate": 1, "catchException": false, "minLatency": 100, "maxLatency": 400, "exceptionMsg": "Exception message!", "statusCode": 404, "diskSpace": 100}
25+
{"isEnabled": false, "failureMode": "latency", "rate": 1, "minLatency": 100, "maxLatency": 400, "exceptionMsg": "Exception message!", "statusCode": 404, "diskSpace": 100}
2626
```
2727
```bash
2828
aws ssm put-parameter --region eu-north-1 --name failureLambdaConfig --type String --overwrite --value "{\"isEnabled\": false, \"failureMode\": \"latency\", \"rate\": 1, \"minLatency\": 100, \"maxLatency\": 400, \"exceptionMsg\": \"Exception message!\", \"statusCode\": 404, \"diskSpace\": 100}"
@@ -38,7 +38,6 @@ Edit the values of your parameter in SSM Parameter Store to use the failure inje
3838
* `isEnabled: false` means that the failure injection module is disabled and no failure is injected.
3939
* `failureMode` selects which failure you want to inject. The options are `latency`, `exception` or `statuscode` as explained below.
4040
* `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.
41-
* `catchException` specifies whether to catch any thrown exceptions or to pass them through to Lambda (**default** is false)
4241
* `minLatency` and `maxLatency` is the span of latency in milliseconds injected into your function when `failureMode` is set to `latency`.
4342
* `exceptionMsg` is the message thrown with the exception created when `failureMode` is set to `exception`.
4443
* `statusCode` is the status code returned by your function when `failureMode` is set to `statuscode`.
@@ -58,9 +57,9 @@ Inspired by Yan Cui's articles on latency injection for AWS Lambda (https://hack
5857

5958
## Changelog
6059

61-
### 2020-02-08 v0.1.1
60+
### 2020-02-13 v0.1.1
6261

63-
* Added a flag to determine whether to catch or release errors before they reach AWS Lambda
62+
* Fixed issue with exception injection not throwing the exception. Thanks to [Jason Barto](https://github.com/jpbarto)!
6463

6564
### 2019-12-30 v0.1.0
6665

lib/failure.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ async function getConfig() {
1717
}
1818
var injectFailure = function (fn) {
1919
return async function () {
20-
var catchFlag = true
21-
2220
try {
2321
let configResponse = await getConfig()
2422
let config = JSON.parse(configResponse)
2523
if (config.isEnabled === true && Math.random() < config.rate) {
26-
catchFlag = config.catchException
2724
if (config.failureMode === 'latency') {
2825
let latencyRange = config.maxLatency - config.minLatency
2926
let setLatency = Math.floor(config.minLatency + Math.random() * latencyRange)
@@ -44,10 +41,9 @@ var injectFailure = function (fn) {
4441
return fn.apply(this, arguments)
4542
} catch (ex) {
4643
console.log(ex)
47-
if (! catchFlag) {
48-
throw ex
49-
}
44+
throw ex
5045
}
5146
}
5247
}
48+
5349
module.exports = injectFailure

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "failure-lambda",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Module for failure injection into AWS Lambda",
55
"main": "./lib/failure.js",
66
"scripts": {

0 commit comments

Comments
 (0)