|
| 1 | +--- |
| 2 | +id: lambda-block-tcp-connection |
| 3 | +title: Lambda Block TCP Connection |
| 4 | +redirect_from: |
| 5 | +- /docs/chaos-engineering/technical-reference/chaos-faults/aws/lambda-block-tcp-connection |
| 6 | +- /docs/chaos-engineering/chaos-faults/aws/lambda-block-tcp-connection |
| 7 | +--- |
| 8 | + |
| 9 | +Lambda Block TCP Connection is an AWS fault that simulates network blocks for TCP connections of a Lambda function. This fault helps you evaluate how your application responds when outbound TCP connections from a Lambda function are blocked. |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +## Use cases |
| 14 | +- Simulate network blocks to test Lambda function resilience. |
| 15 | +- Evaluate the impact of blocked TCP connections on application performance and error handling. |
| 16 | +- Test fallback mechanisms and error reporting in serverless architectures. |
| 17 | + |
| 18 | +### Prerequisites |
| 19 | +- Kubernetes >= 1.17 |
| 20 | +- The Lambda function must be up and running. |
| 21 | +- Kubernetes secret must have the AWS access configuration (key) in the `CHAOS_NAMESPACE`. Below is a sample secret file: |
| 22 | + ```yaml |
| 23 | + apiVersion: v1 |
| 24 | + kind: Secret |
| 25 | + metadata: |
| 26 | + name: cloud-secret |
| 27 | + type: Opaque |
| 28 | + stringData: |
| 29 | + cloud_config.yml: |- |
| 30 | + # Add the cloud AWS credentials respectively |
| 31 | + [default] |
| 32 | + aws_access_key_id = XXXXXXXXXXXXXXXXXXX |
| 33 | + aws_secret_access_key = XXXXXXXXXXXXXXX |
| 34 | + ``` |
| 35 | +
|
| 36 | +:::tip |
| 37 | +HCE recommends that you use the same secret name, that is, `cloud-secret`. Otherwise, you will need to update the `AWS_SHARED_CREDENTIALS_FILE` environment variable in the fault template with the new secret name and you won't be able to use the default health check probes. |
| 38 | +::: |
| 39 | + |
| 40 | +Below is an example AWS policy to execute the fault. |
| 41 | + |
| 42 | +```json |
| 43 | +{ |
| 44 | + "Version": "2012-10-17", |
| 45 | + "Statement": [ |
| 46 | + { |
| 47 | + "Effect": "Allow", |
| 48 | + "Action": [ |
| 49 | + "lambda:GetFunction", |
| 50 | + "lambda:GetFunctionConfiguration", |
| 51 | + "lambda:UpdateFunctionConfiguration" |
| 52 | + ], |
| 53 | + "Resource": "*" |
| 54 | + } |
| 55 | + ] |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +:::info note |
| 60 | +- Go to [superset permission/policy](/docs/chaos-engineering/faults/chaos-faults/aws/security-configurations/policy-for-all-aws-faults) to execute all AWS faults. |
| 61 | +- Go to the [common tunables](/docs/chaos-engineering/faults/chaos-faults/common-tunables-for-all-faults) and [AWS-specific tunables](/docs/chaos-engineering/faults/chaos-faults/aws/aws-fault-tunables) to tune the common tunables for all faults and AWS-specific tunables. |
| 62 | +- Go to [AWS named profile for chaos](/docs/chaos-engineering/faults/chaos-faults/aws/security-configurations/aws-switch-profile) to use a different profile for AWS faults. |
| 63 | +- Currently, it is supported in Python; support for other languages is coming soon. |
| 64 | +::: |
| 65 | + |
| 66 | +### Mandatory tunables |
| 67 | + |
| 68 | +<table> |
| 69 | + <caption>Lambda Chaos Fault Tunables</caption> |
| 70 | + <thead> |
| 71 | + <tr> |
| 72 | + <th>Tunable</th> |
| 73 | + <th>Description</th> |
| 74 | + <th>Notes</th> |
| 75 | + </tr> |
| 76 | + </thead> |
| 77 | + <tbody> |
| 78 | + <tr> |
| 79 | + <td>FUNCTION_NAME</td> |
| 80 | + <td>Name of the target Lambda function.</td> |
| 81 | + <td>For example, <code>test-function</code>. For more information, go to <a href="#function-name">function name</a>.</td> |
| 82 | + </tr> |
| 83 | + <tr> |
| 84 | + <td>REGION</td> |
| 85 | + <td>The AWS region where the Lambda function is deployed.</td> |
| 86 | + <td>For example, <code>us-east-1</code>. For more information, go to <a href="/docs/chaos-engineering/faults/chaos-faults/aws/aws-fault-tunables">region</a>.</td> |
| 87 | + </tr> |
| 88 | + <tr> |
| 89 | + <td>TARGET_HOSTNAMES</td> |
| 90 | + <td>Comma-separated list of hostnames to block TCP connections to.</td> |
| 91 | + <td>For example, <code>example.com,api.example.com</code>. For more information, go to <a href="#target-hostnames">target hostnames</a>.</td> |
| 92 | + </tr> |
| 93 | + </tbody> |
| 94 | +</table> |
| 95 | + |
| 96 | + |
| 97 | +### Optional tunables |
| 98 | + |
| 99 | +<table> |
| 100 | + <caption>Common Chaos Tunables</caption> |
| 101 | + <thead> |
| 102 | + <tr> |
| 103 | + <th>Tunable</th> |
| 104 | + <th>Description</th> |
| 105 | + <th>Notes</th> |
| 106 | + </tr> |
| 107 | + </thead> |
| 108 | + <tbody> |
| 109 | + <tr> |
| 110 | + <td>TOTAL_CHAOS_DURATION</td> |
| 111 | + <td>Duration for which chaos is injected (in seconds).</td> |
| 112 | + <td>Default: 30 s. For more information, go to <a href="/docs/chaos-engineering/faults/chaos-faults/common-tunables-for-all-faults#duration-of-the-chaos">duration of the chaos</a>.</td> |
| 113 | + </tr> |
| 114 | + <tr> |
| 115 | + <td>CHAOS_INTERVAL</td> |
| 116 | + <td>The interval (in seconds) between successive network block attempts.</td> |
| 117 | + <td>Default: 30 s. For more information, go to <a href="/docs/chaos-engineering/faults/chaos-faults/common-tunables-for-all-faults#chaos-interval">chaos interval</a>.</td> |
| 118 | + </tr> |
| 119 | + <tr> |
| 120 | + <td>AWS_SHARED_CREDENTIALS_FILE</td> |
| 121 | + <td>Path to the AWS secret credentials.</td> |
| 122 | + <td>Default: <code>/tmp/cloud_config.yml</code>. For more information, go to <a href="/docs/chaos-engineering/faults/chaos-faults/aws/aws-fault-tunables">AWS shared credentials file</a>.</td> |
| 123 | + </tr> |
| 124 | + <tr> |
| 125 | + <td>RAMP_TIME</td> |
| 126 | + <td>Period to wait before and after injecting chaos (in seconds).</td> |
| 127 | + <td>Optional. For more information, go to <a href="/docs/chaos-engineering/faults/chaos-faults/common-tunables-for-all-faults#ramp-time">ramp time</a>.</td> |
| 128 | + </tr> |
| 129 | + </tbody> |
| 130 | +</table> |
| 131 | + |
| 132 | + |
| 133 | +#### Target Hostnames |
| 134 | + |
| 135 | +The `TARGET_HOSTNAMES` environment variable defines the list of hostnames to which TCP connections should be blocked from the target Lambda function during chaos execution. |
| 136 | + |
| 137 | + |
| 138 | +Block TCP connections to specific hostnames from a Lambda function. |
| 139 | + |
| 140 | +[embedmd]:# (./static/manifests/lambda-block-tcp-connection/target-hostnames.yaml yaml) |
| 141 | +```yaml |
| 142 | +--- |
| 143 | +# Block TCP connections to specific hostnames from a Lambda function |
| 144 | +apiVersion: litmuschaos.io/v1alpha1 |
| 145 | +kind: ChaosEngine |
| 146 | +metadata: |
| 147 | + name: lambda-block-tcp-connection |
| 148 | +spec: |
| 149 | + engineState: "active" |
| 150 | + chaosServiceAccount: litmus-admin |
| 151 | + experiments: |
| 152 | + - name: lambda-block-tcp-connection |
| 153 | + spec: |
| 154 | + components: |
| 155 | + env: |
| 156 | + - name: TARGET_HOSTNAMES |
| 157 | + value: 'example.com,api.example.com' |
| 158 | +``` |
| 159 | + |
| 160 | +#### Function Name |
| 161 | + |
| 162 | +The `FUNCTION_NAME` environment variable specifies the name of the target AWS Lambda function whose host will be subjected to chaos. |
| 163 | + |
| 164 | +[embedmd]:# (./static/manifests/lambda-block-tcp-connection/function-name.yaml yaml) |
| 165 | +```yaml |
| 166 | +--- |
| 167 | +# Block TCP connections from a specific Lambda function |
| 168 | +apiVersion: litmuschaos.io/v1alpha1 |
| 169 | +kind: ChaosEngine |
| 170 | +metadata: |
| 171 | + name: lambda-block-tcp-connection |
| 172 | +spec: |
| 173 | + engineState: "active" |
| 174 | + chaosServiceAccount: litmus-admin |
| 175 | + experiments: |
| 176 | + - name: lambda-block-tcp-connection |
| 177 | + spec: |
| 178 | + components: |
| 179 | + env: |
| 180 | + - name: FUNCTION_NAME |
| 181 | + value: 'test-function' |
| 182 | +``` |
0 commit comments