> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/resilience-testing/chaos-engineering/faults/chaos-fault-categories/aws/ec2-cpu-hog.md).

# EC2 CPU hog

EC2 CPU hog is an AWS chaos fault that drives a configurable number of CPU cores to a configurable load percentage inside a target EC2 instance for a configurable duration. The fault dispatches the stress workload via AWS Systems Manager Run Command, so the target instance must have the SSM Agent installed and an IAM role that permits SSM messages.

Use this fault to test how a workload reacts when its host is CPU-starved: does autoscaling react, do latency-sensitive paths break SLO, does the load balancer detach the instance because of failing health checks?

{% hint style="info" %}
**RUN YOUR FIRST EXPERIMENT**

If you have not configured the chaos infrastructure yet, go to [Quickstart](/resilience-testing/chaos-engineering/new-to-chaos-engineering/quickstart.md) to install the chaos infrastructure and run an experiment end to end.
{% endhint %}

***

### Use cases <a href="#use-cases" id="use-cases"></a>

Run this fault when you want to answer concrete questions like:

* **Latency under CPU pressure:** When all cores are saturated, does p99 latency stay within SLO?
* **Autoscaling triggers:** Do CloudWatch CPU alarms fire and does the ASG add capacity in the expected window?
* **Health-check correctness:** Does the target group detach the saturated instance, and does it reattach when the fault ends?
* **Co-tenant workloads:** When one workload monopolizes CPU, do neighbouring workloads still meet their SLOs?
* **Burst-credit exhaustion (T-family):** For burstable instance types (`t3`, `t4g`), does sustained 100% CPU exhaust burst credits and degrade further?

***

### Prerequisites <a href="#prerequisites" id="prerequisites"></a>

* **Kubernetes version:** 1.21 or later for the chaos infrastructure cluster.
* **Target instance is reachable via SSM:** The instance has the SSM Agent running and an instance profile with `AmazonSSMManagedInstanceCore` (or equivalent). Confirm with `aws ssm describe-instance-information --filters "Key=InstanceIds,Values=<id>"`.
* **Selector provided:** Either `EC2_INSTANCE_ID` or `EC2_INSTANCE_TAG` is set.
* **AWS credentials available:** Either an AWS credentials file uploaded as a **File Secret in Harness Secret Manager** (see Authentication below) or IRSA on the chaos infrastructure service account.
* **IAM permissions granted:** The credentials or role include the SSM and EC2 permissions listed below.

***

### Supported environments <a href="#supported-environments" id="supported-environments"></a>

| Platform                                    | Support status                                             |
| ------------------------------------------- | ---------------------------------------------------------- |
| Amazon EC2 (Linux instances with SSM Agent) | Supported                                                  |
| Amazon EKS managed worker nodes             | Supported (if SSM Agent is installed)                      |
| Amazon EKS self-managed worker nodes        | Supported (if SSM Agent is installed)                      |
| Targeting by tag                            | Supported via `EC2_INSTANCE_TAG`                           |
| Targeting by ID                             | Supported via `EC2_INSTANCE_ID`                            |
| Burstable instance types (T family)         | Supported (be aware of credit exhaustion; see Limitations) |
| Windows instances                           | Not supported (Linux-only stress payload)                  |

***

### Permissions required <a href="#permissions-required" id="permissions-required"></a>

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ec2:DescribeInstances",
        "ec2:DescribeInstanceStatus"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "ssm:SendCommand",
        "ssm:CancelCommand",
        "ssm:GetCommandInvocation",
        "ssm:DescribeInstanceInformation",
        "ssm:GetDocument",
        "ssm:DescribeDocument"
      ],
      "Resource": "*"
    }
  ]
}
```

Go to [common policy for all AWS faults](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/aws/security-configurations/policy-for-all-aws-faults.md) to use a single superset IAM policy.

***

### Authentication <a href="#authentication" id="authentication"></a>

The fault supports three credential delivery models. Pick one based on how your chaos infrastructure is deployed.

| Method                                | When to use it                                                                 | How to configure                                                                                                                                                                                                                    |
| ------------------------------------- | ------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Harness Secret Manager file secret    | Chaos infrastructure runs outside EKS, or you want explicit static credentials | Upload the AWS credentials file as a **File Secret** in Harness Secret Manager and reference its identifier via `AWS_AUTHENTICATION_SECRET`                                                                                         |
| IAM Roles for Service Accounts (IRSA) | Chaos infrastructure runs in EKS and uses an OIDC-bound service account        | No tunable changes; the chaos pod inherits the role automatically. Go to [AWS IAM integration](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/aws/security-configurations/aws-iam-integration.md) to set it up |
| Assume role                           | The fault needs to act in a different account or with elevated permissions     | Set `ASSUME_ROLE_ARN` to the role ARN; the chaos pod assumes the role on top of its base credentials                                                                                                                                |

When using the Harness Secret Manager method, the File Secret should contain an AWS credentials file in the standard `~/.aws/credentials` format:

```ini
[default]
aws_access_key_id = REPLACE_WITH_ACCESS_KEY_ID
aws_secret_access_key = REPLACE_WITH_SECRET_ACCESS_KEY
```

Upload this file as a **File Secret** in Harness Secret Manager (Project Setup → Secrets → New File Secret), and pass the secret identifier in `AWS_AUTHENTICATION_SECRET`.

***

### Fault tunables <a href="#fault-tunables" id="fault-tunables"></a>

**Required parameters**

| Tunable                                   | Description                                                | Default    |
| ----------------------------------------- | ---------------------------------------------------------- | ---------- |
| `REGION`                                  | AWS region that hosts the target instance.                 | (required) |
| `EC2_INSTANCE_ID` *or* `EC2_INSTANCE_TAG` | One of these must be set to select the target instance(s). | `""`       |

**Chaos parameters**

| Tunable                  | Description                                                                                                                                                                                                      | Default    |
| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- |
| `CPU_CORES`              | Number of CPU cores to hog. `0` hogs all available cores.                                                                                                                                                        | `0`        |
| `CPU_LOAD`               | Percentage of CPU load to generate per core (0-100).                                                                                                                                                             | `100`      |
| `TOTAL_CHAOS_DURATION`   | Duration of the fault in seconds.                                                                                                                                                                                | `60`       |
| `INSTANCE_AFFECTED_PERC` | Percentage of matching instances to target (only with `EC2_INSTANCE_TAG`). `0` targets one instance.                                                                                                             | `0`        |
| `INSTALL_DEPENDENCIES`   | Install the in-instance stress tool if missing. Set to `False` to skip.                                                                                                                                          | `True`     |
| `PROXY`                  | HTTP/HTTPS proxy used by the in-instance installer (for example `https_proxy=http://proxy.server:3128`).                                                                                                         | `""`       |
| `SEQUENCE`               | Order in which multiple instances are processed: `parallel` or `serial`.                                                                                                                                         | `parallel` |
| `RAMP_TIME`              | Wait period in seconds before and after the fault. Go to [ramp time](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/common-tunables-for-all-faults.md#ramp-time) to read how it is applied. | `0`        |

**Authentication**

| Tunable                     | Description                                                                                                                       | Default |
| --------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `ASSUME_ROLE_ARN`           | ARN of an IAM role to assume on top of the base credentials.                                                                      | `""`    |
| `AWS_AUTHENTICATION_SECRET` | Identifier of the **File Secret in Harness Secret Manager** that contains the AWS credentials file. Not required when using IRSA. | `""`    |

Tunables that apply to every fault are documented in [common tunables for all faults](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/common-tunables-for-all-faults.md).

{% hint style="info" %}
**TUNE CPU\_CORES TO YOUR BLAST RADIUS**

Setting `CPU_CORES=0` (all cores) is the most severe option. For a softer test, set `CPU_CORES` to half of the instance's vCPU count and observe whether the workload starts to degrade before saturation.
{% endhint %}

***

### Fault execution in brief <a href="#fault-execution-in-brief" id="fault-execution-in-brief"></a>

Sends an SSM Run Command to the selected instance(s) in `REGION` that spawns a CPU-stress workload pinned to `CPU_CORES` cores at `CPU_LOAD` percent each for `TOTAL_CHAOS_DURATION` seconds.

***

### Expected behavior during fault execution <a href="#expected-behavior-during-fault-execution" id="expected-behavior-during-fault-execution"></a>

* Per-core CPU utilization on the target instance climbs to `CPU_LOAD` percent across `CPU_CORES` cores.
* CloudWatch `CPUUtilization` rises to the corresponding fraction of overall capacity.
* Latency-sensitive workloads typically see p99 latency spike; CPU-bound throughput drops.
* For burstable instance types, CPU credits drain rapidly; once exhausted, baseline performance degrades further.
* Load balancer health checks may begin to fail if they share CPU with the workload.

{% hint style="info" %}
**WHEN THE FAULT ENDS**

The chaos pod terminates the stress workload. CPU utilization returns to baseline within seconds; burst credits replenish according to the instance's credit accrual rate.
{% endhint %}

#### Signals to watch <a href="#signals-to-watch" id="signals-to-watch"></a>

* **CPU utilization:** Use a [Prometheus probe](/resilience-testing/chaos-engineering/use-chaos-engineering/probes/apm-probes.md) on `aws_ec2_cpuutilization_average` (CloudWatch exporter) to confirm the spike.
* **Application latency:** Use an [HTTP probe](/resilience-testing/chaos-engineering/use-chaos-engineering/probes/http-probe.md) to detect latency regression.
* **Burst credits:** For T-family instances, watch `aws_ec2_cpucredit_balance_minimum` to confirm credit exhaustion.

***

### Verify the fault execution effect <a href="#verify-the-fault-execution-effect" id="verify-the-fault-execution-effect"></a>

While the experiment is running:

1. **Check CPU on the instance via SSM.**

   ```bash
   aws ssm send-command \
     --region <region> \
     --instance-ids <id> \
     --document-name AWS-RunShellScript \
     --parameters 'commands=["top -bn1 | head -20"]'
   ```
2. **Confirm CloudWatch metric spike.**

   ```bash
   aws cloudwatch get-metric-statistics \
     --namespace AWS/EC2 --metric-name CPUUtilization \
     --dimensions Name=InstanceId,Value=<id> \
     --start-time $(date -u -v-5M +%FT%TZ) --end-time $(date -u +%FT%TZ) \
     --period 60 --statistics Average
   ```

***

### Recovery and cleanup <a href="#recovery-and-cleanup" id="recovery-and-cleanup"></a>

* **End of duration:** The chaos pod terminates the stress workload.
* **Abort the experiment:** Stopping the experiment from Chaos Studio cancels the in-flight SSM command.
* **Manual recovery:** If the stress workload outlives the experiment (rare), kill it via SSM: `pkill -f stress` or `pkill -f <stress-binary>`.

***

### Limitations <a href="#limitations" id="limitations"></a>

* **Linux-only payload:** This fault stresses Linux instances. For Windows hosts, use `windows-ec2-cpu-hog`.
* **SSM Agent required:** Instances without the SSM Agent online cannot be targeted.
* **Burst-credit consumption:** On T-family instances, credits are consumed by the fault and may not be fully replenished by the time the next experiment runs. Allow recovery time between runs.
* **Workload eviction:** On EKS nodes, severe CPU pressure may cause kubelet to evict pods. Use `INSTANCE_AFFECTED_PERC` and `CPU_CORES` carefully on production-like clusters.

***

### Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

<details>

<summary>EC2 CPU hog experiment fails with InvalidInstanceId in Harness Chaos Engineering</summary>

The SSM Agent is not online for the target instance. Confirm with aws ssm describe-instance-information --filters 'Key=InstanceIds,Values='. If the instance is missing, install the SSM Agent and attach an instance profile that includes AmazonSSMManagedInstanceCore.

</details>

<details>

<summary>EC2 CPU hog runs but CPUUtilization metric stays flat</summary>

The most common causes are: the in-instance stress tool failed to install (set INSTALL\_DEPENDENCIES=True and verify network egress from the instance, or use PROXY); CPU\_CORES is greater than the instance vCPU count; or CloudWatch metric resolution is coarse and is averaging out the spike. Run 'top' via SSM during the fault to confirm load locally before relying on CloudWatch.

</details>

<details>

<summary>EC2 CPU hog fails with AccessDeniedException calling ssm:SendCommand</summary>

The chaos pod's IAM principal lacks ssm:SendCommand or related SSM permissions. Add ssm:SendCommand, ssm:GetCommandInvocation, ssm:DescribeInstanceInformation, ssm:CancelCommand, ssm:GetDocument, and ssm:DescribeDocument to the policy. If using ASSUME\_ROLE\_ARN, confirm the trust policy allows the source identity.

</details>

***

### Related faults <a href="#related-faults" id="related-faults"></a>

* [EC2 memory hog](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/aws/ec2-memory-hog.md): Stress memory instead of CPU.
* [EC2 IO stress](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/aws/ec2-io-stress.md): Stress filesystem IO instead of CPU.
* [EC2 process kill](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/aws/ec2-process-kill.md): Kill a specific process instead of saturating CPU.
* [Windows EC2 CPU hog](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/aws/windows-ec2-cpu-hog.md): CPU stress for Windows instances.
* [Common AWS fault tunables](/resilience-testing/chaos-engineering/faults/chaos-fault-categories/aws/aws-fault-tunables.md): Shared environment variables for AWS faults.
