|
1 |
| -## My Project |
| 1 | +# AWS Lambda Actions for AWS FIS |
2 | 2 |
|
3 |
| -TODO: Fill this README out! |
| 3 | +## Introduction |
| 4 | +The AWS Fault Injection Service (FIS) supports AWS Lambda Actions which allows you to inject faults into |
| 5 | +the Lambda execution environments. As part of their resilience plan, Lambda fault actions |
| 6 | +enable you, our AWS customers, to demonstrate that their Lambda-based applications operate |
| 7 | +as expected during periods of AWS impairment, in response to misconfigurations, or in |
| 8 | +response to bad data. |
4 | 9 |
|
5 |
| -Be sure to: |
| 10 | +## Prerequisites |
| 11 | +- [CDK Toolkit](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html) & bootstrapped AWS environment |
| 12 | +- [docker](https://docs.docker.com/engine/install/) |
| 13 | +- [mvn](https://maven.apache.org/run.html) |
6 | 14 |
|
7 |
| -* Change the title in this README |
8 |
| -* Edit your repository description on GitHub |
| 15 | +> **[!IMPORTANT]** |
| 16 | +> You need to deploy the stack to an AWS Region where [AWS FIS is supported](https://docs.aws.amazon.com/general/latest/gr/fis.html). |
9 | 17 |
|
10 |
| -## Security |
| 18 | +> **[!IMPORTANT]** |
| 19 | +> This application deploy publicly available endpoints you'll use to interact with the application. Don't forget to cleanup the deployment following steps below to avoid unnecessary costs. |
11 | 20 |
|
12 |
| -See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information. |
| 21 | +## Solution Overview |
13 | 22 |
|
14 |
| -## License |
| 23 | +### Sample Application |
15 | 24 |
|
16 |
| -This library is licensed under the MIT-0 License. See the LICENSE file. |
| 25 | +This repository contains three (3) serverless applications and FIS experiment templates using FIS Lambda Actions. |
| 26 | + |
| 27 | +Sample applications are simple CRUD APIs that allow you to manage orders. They are built using Amazon API Gateway, AWS Lambda, and Amazon DynamoDB. It provides simple Create, Read, Update, and Delete (CRUD) functionality to manage orders. |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +The different APIs and its Lambda functions are implemented using three different runtimes: Node.js, Python and Java. |
| 32 | + |
| 33 | +### FIS Templates |
| 34 | +This repository also deploys the FIS experiment templates which carry out the Lambda actions. Separate experiment templates will be deployed for each of the sample applications. There will be two FIS templates per sample application. |
| 35 | + |
| 36 | +1. **Lambda Latency Injection Fault** - this FIS template utilize the *[aws:lambda:invocation-add-delay](https://docs.aws.amazon.com/fis/latest/userguide/fis-actions-reference.html#invocation-add-delay)* action. |
| 37 | +It is configured to inject 2000ms (2 seconds) latency into 100% of the request for 10 minutes. |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +2. **Lambda Http Integration Response Fault** - FIS template utilize the*[aws:lambda:invocation-http-integration-response](https://docs.aws.amazon.com/fis/latest/userguide/fis-actions-reference.html#invocation-http-integration-response)*. |
| 42 | + |
| 43 | +It is configured to inject error responses of status code 500 for 100% of the request for 10 minutes. It will also prevent the actual execution of the Lambda Function. |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | +### Observability Dashboards |
| 48 | +Repository also implements observability dashboards for each of the CRUD applications deployed. |
| 49 | + |
| 50 | + |
| 51 | +## Getting started |
| 52 | + |
| 53 | +The CDK code deploys all necessary resources for the experiments. |
| 54 | + |
| 55 | +See the official [AWS FIS Actions](https://docs.aws.amazon.com/fis/latest/userguide/fis-actions-reference.html) documentation page for more information. |
| 56 | + |
| 57 | +### Setup |
| 58 | + |
| 59 | +#### Deploy resources |
| 60 | +To deploy resources, please execute the following command in the CLI environment, where you have already logged into the AWS account. |
| 61 | + |
| 62 | +``` |
| 63 | +cd cdk-lambda-chaos |
| 64 | +npm ci |
| 65 | +cdk deploy --all --parameters FisLambdaAPIs:fisLambdaLayerARN='arn:aws:lambda:us-east-1:211125607513:layer:aws-fis-extension-x86_64:9' |
| 66 | +cd .. |
| 67 | +``` |
| 68 | + |
| 69 | +Once deployment is completed - you'll be presented with the API endpoints. Please make a note of them. |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | +#### Install dependencies for load generation |
| 74 | +Please execute the following command in the CLI environment |
| 75 | + |
| 76 | +``` |
| 77 | +cd load-generation |
| 78 | +npm install -g artillery@latest |
| 79 | +npm ci |
| 80 | +
|
| 81 | +``` |
| 82 | + |
| 83 | +#### Configure Variables for the experiment |
| 84 | +<!-- FisLambdaAPIs stack outputs the URL of deployed API which is exposing the AWS Lambda functions that you want to run the chaos experiments on. The screenshot below shows the output from FisLambdaAPIs stack. You can take the URL as highlighted in the screenshot as an example: |
| 85 | + --> |
| 86 | + |
| 87 | +As the next step, you need to configure environment variable API_URL with the API endpoint of the CRUD application that you want to run the chaos experiment for. |
| 88 | + |
| 89 | +Use the API endpoint you've captured before and remove the trailing "/" from the url. Then set this as an environment variable as shown below. |
17 | 90 |
|
| 91 | +``` |
| 92 | +export API_URL='https://<api_id>.execute-api.<region>.amazonaws.com/prod' |
| 93 | +``` |
| 94 | + |
| 95 | +This would be used by the Artillery load generation script. |
| 96 | + |
| 97 | +**NOTE:** *You just have to set the base path without leading '/' as '/' is added within the load generation configuration.* |
| 98 | + |
| 99 | +### Run the experiment |
| 100 | + |
| 101 | +#### Generate load |
| 102 | +**Note!** *Make sure to you have set the API_URL environment variable as shown above.* |
| 103 | + |
| 104 | +Before you run the chaos engineering experiments using FIS, ensure that your application has reached steady state. See [Basic principles and guidelines](https://docs.aws.amazon.com/fis/latest/userguide/getting-started-planning.html#planning-basic-principles) to learn more on this. In this example, you can run load generation using following command to achieve steady state: |
| 105 | + |
| 106 | +``` |
| 107 | +artillery run load-generation-config.yml |
| 108 | +``` |
| 109 | + |
| 110 | +By default, this sends 4 requests per second for 10 minutes. You can change the during as well as number of requests for load generation in ``load-generation-config.yml`` file. See [Artillery documentation](https://www.artillery.io/docs/get-started/first-test#define-load-phases) for more details. |
| 111 | + |
| 112 | +Go to the [AWS CloudWatch Console](https://console.aws.amazon.com/cloudwatch/) where you'll find three dashboards. |
| 113 | + |
| 114 | + |
| 115 | +Select the dashboard for the the application you are testing and observe the steady state. |
| 116 | + |
| 117 | + |
| 118 | +#### Start the experiment |
| 119 | +Go to the [AWS Resilience HUB Console](https://console.aws.amazon.com/resiliencehub/home). Navigate to the **Resilience testing** and select **Experiment templates**. You'll see the list of the FIS Experiment Templates deployed for you. |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | +Select FIS experiment template for the experiment and integration you'd like execute and press **Start Experiment** again press on **Start Experiment** button on the next screen to run the experiments. |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | +#### Monitor results |
| 129 | + |
| 130 | +Once you have run the load generation script and started the experiment, you can observe your application's behavior by looking at different metrics included in the [CloudWatch Dashboards](https://console.aws.amazon.com/cloudwatch/). To get a holistic view of your application behavior, this dashboard includes |
| 131 | +* metrics from Artillery load generation including number of requests and corresponding responses received, latency of response, any errors recorded by load generation script. This represents the user's perspective of your application. |
| 132 | +* corresponding metrics from API Gateway and Lambda Function that comprise the API we are invoking from load generation script and, |
| 133 | +* metrics from FIS extension showing the number of faults injected by the experiment. |
| 134 | + |
| 135 | +Below is an example of running the 'Lambda Latency Injection Fault' experiment template. |
| 136 | + |
| 137 | + |
| 138 | + |
| 139 | +The Dashboard is organized in four rows three columns: |
| 140 | +* First row represents the requests from load generation, corresponding API Gateway request count and corresponding Lambda invocations. They should represent and same count for steady state. |
| 141 | +* Second row shows response times recorded by load generation, latency from API Gateway and Lambda duration. You should see a correlation among these metrics when you run *aws:lambda:invocation-add-delay* experiment. |
| 142 | +* Third row shows API errors recorded by the load generation script, errors reported by API Gateway and errors in Lambda function invocations. If you run *aws:lambda:invocation-http-integration-response* experiment, you should see correlation in metrics in this row. |
| 143 | +* The last row represents *FaultInjected* metric. Based on the experiment you are running, you should see a correlation with either "FIS FaultInjected Invocation Delay" or "FIS FaultInjected HTTP Integration Response" graph. |
| 144 | + |
| 145 | +NOTE: This dashboard includes only *FaultInjected* metric. You can explore [all EMF metrics emitted by AWS FIS Extension](https://docs.aws.amazon.com/fis/latest/userguide/use-lambda-actions.html) in *aws-fis-extension* Custom namespace in CloudWatch. |
| 146 | + |
| 147 | + |
| 148 | +### Cleanup |
| 149 | +Run the following command from the `cdk-lambda-chaos` folder. |
| 150 | +``` |
| 151 | +cdk destroy --all |
| 152 | +``` |
| 153 | + |
| 154 | +## Contributing |
| 155 | +See [CONTRIBUTING](CONTRIBUTING.md) for more information. |
| 156 | + |
| 157 | +## License |
| 158 | +This library is licensed under the MIT-0 License. See the LICENSE file. |
0 commit comments