> For the complete documentation index, see [llms.txt](https://docs.octoxlabs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.octoxlabs.com/action-center/aws/ec2-instance-right-sizing.md).

# EC2 Instance Right Sizing

Changes the instance type of every EC2 instance that the workflow passes to it. The job reads each instance's type and state from AWS first (live state), stops a running instance, changes the type and, if you want, starts it again.

{% hint style="warning" %}
A running instance is stopped for the duration of the change, so it is unavailable until it starts again. If **Auto restart** is off, it stays stopped.
{% endhint %}

### Before you begin

* AWS credentials (access key ID and secret access key) that are allowed to call the AWS API actions listed below. Enter them in the node or save them once in [Action Center Settings](broken://pages/ea41765c908dc2733f18c3a1329cd7501b60f6da) (the **AWS** group has one tab per job, so each job needs its own defaults).
* Asset type: `device` only.
* Required column: `Specifics.aws-ec2.InstanceId`. Only devices that have a value in this column are used; the rest are left out.
* AWS API actions the job calls: `DescribeInstances`, `StopInstances`, `ModifyInstanceAttribute`, `StartInstances` (EC2), plus the instance-stopped waiter.

### Settings

The node form shows these fields. Field labels are generated from the field names, so they appear as listed here. The AWS access key ID and secret access key are plain text fields, not masked fields.

| Setting               | Type    | Required | Default | Description                                                                                      |
| --------------------- | ------- | -------- | ------- | ------------------------------------------------------------------------------------------------ |
| Aws access key id     | Text    | Yes      | None    | AWS access key ID the job signs its requests with. Not masked in the form or in Settings.        |
| Aws secret access key | Text    | Yes      | None    | Secret access key for the key ID above. Not masked in the form or in Settings.                   |
| Aws region            | Text    | Yes      | None    | AWS region the client connects to, for example `eu-west-1`. The value may be empty.              |
| New instance type     | Text    | Yes      | None    | Instance type to switch to, for example `t3.medium`.                                             |
| Auto restart          | Boolean | No       | On      | Start the instance again after the change, but only if it was running before the job stopped it. |

### How it works

The job reads the instance ID from every incoming device asset that has one and sends the IDs to AWS in batches of 50 instances per request.

For each batch the job calls `DescribeInstances` and handles each instance in turn:

* If the instance already has the new type, it is skipped.
* If it is running, the job stops it and waits until it is stopped.
* The job changes the instance type with `ModifyInstanceAttribute`.
* If **Auto restart** is on and the instance was running before, the job starts it again. An instance that was already stopped stays stopped.

Errors are handled per instance: a failed describe or resize is written to the run log as an error and the job moves on to the next one. The job does not fail because of them, so check the audit log after a run. The job fails only with `EC2 instance ids not found` when no asset has an instance ID.

The job does not change the asset data. It passes the incoming assets unchanged to the next node.

### Example

Put the job after a condition node whose saved query returns the instances to resize.

| Setting               | Value                        |
| --------------------- | ---------------------------- |
| Aws access key id     | `YOUR_AWS_ACCESS_KEY_ID`     |
| Aws secret access key | `YOUR_AWS_SECRET_ACCESS_KEY` |
| Aws region            | `eu-west-1`                  |
| New instance type     | `t3.medium`                  |
| Auto restart          | On                           |

### What's next?

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>About Action Center</strong></td><td>Workflows, triggers, conditions and job nodes.</td><td><a href="broken://pages/94a9962c87c4d45ae1ec3bb263b516656f67490d">Broken link</a></td></tr><tr><td><strong>Action Center Settings</strong></td><td>Save the AWS connection values as job defaults.</td><td><a href="broken://pages/ea41765c908dc2733f18c3a1329cd7501b60f6da">Broken link</a></td></tr></tbody></table>

{% hint style="info" %}
Available starting from version 6.3.0.
{% endhint %}
