Skip to content

Commit e4806c7

Browse files
authored
Merge pull request #1612 from rundeck/change-ec2-size
Change EC2 Size Solution
2 parents c32f150 + 8bc2d6f commit e4806c7

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed
33.9 KB
Loading

docs/.vuepress/sidebar-menus/learning.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ export default [{
259259
collapsible: true,
260260
children: [
261261
{ link: '/learning/solutions/cost-management/index.md', text: 'Solution Summary' },
262+
{ link: '/learning/solutions/cost-management/aws-change-ec2-size.md', text:'AWS - Change EC2 Size' },
262263
{ link: '/learning/solutions/cost-management/aws-list-unused-vpcs.md', text: 'AWS - Identify Unused VPCs' },
263264
{ link: '/learning/solutions/cost-management/aws-list-unused-lambda.md', text: 'AWS - Identify Unused Lambda Functions' },
264265
{ link: '/learning/solutions/cost-management/aws-list-unused-securitygroups.md', text: 'AWS - Identify Unused Security Groups' },
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# AWS - Change EC2 Instance Size
2+
3+
## Description
4+
5+
This automation job allows you to safely modify the instance type of an EC2 instance. The job handles the complete workflow including stopping the instance, changing its size, and optionally restarting it.
6+
7+
## Prerequisites
8+
9+
- Turn on "[Runner as Node](/administration/runner/runner-management/node-dispatch.html#runner-as-a-node)" setting on your Runner.
10+
- This requires version 5.8.0 or higher. Adjustments to Node tab may be required for earlier versions.
11+
- AWS CLI installed on your runner.
12+
- AWS EC2 Node Source configured with "Show only Running instances" set to "No". (Details below)
13+
- Sufficient AWS IAM permissions to modify EC2 instances
14+
15+
## AWS IAM Permissions
16+
17+
The AWS IAM role or user associated with this job requires the following permissions:
18+
19+
- `ec2:StopInstances`
20+
- `ec2:StartInstances`
21+
- `ec2:ModifyInstanceAttribute`
22+
- `ec2:DescribeInstances`
23+
- `ec2:DescribeInstanceTypeOfferings`
24+
25+
```json
26+
{
27+
"Version": "2012-10-17",
28+
"Statement": [
29+
{
30+
"Effect": "Allow",
31+
"Action": [
32+
"ec2:StopInstances",
33+
"ec2:StartInstances",
34+
"ec2:ModifyInstanceAttribute",
35+
"ec2:DescribeInstances",
36+
"ec2:DescribeInstanceTypeOfferings"
37+
],
38+
"Resource": "*"
39+
}
40+
]
41+
}
42+
```
43+
44+
## Important Node Source Configuration
45+
46+
When using this job with EC2 instances, a specific Node Source configuration is required:
47+
48+
**Why**: EC2 instances must be in a stopped state before their instance type can be modified. Therefore, the Node Source must be able to discover both running AND stopped instances.
49+
50+
**Required Setting**:
51+
- In your EC2 Node Source configuration
52+
- Set "Show only Running Instances" to "No"
53+
54+
If this setting remains set to "Yes", stopped instances will not be visible to Rundeck and the job will fail to locate the target instance.
55+
56+
![](/assets/img/solutions-aws-change-ec2-nodesource.png)
57+
58+
## Job Options
59+
60+
| Option Name | Description | Required | Default |
61+
|------------|-------------|----------|---------|
62+
| `new-instance-type` | The target EC2 instance type | Yes | N/A |
63+
| `start-instance` | Whether to restart the instance after changing size | Yes | Yes |
64+
65+
Available instance types include various sizes across these families:
66+
- General Purpose: t3, m5
67+
- Compute Optimized: c5
68+
- Memory Optimized: r5
69+
- Storage Optimized: i3
70+
- Accelerated Computing: p3, g4dn
71+
72+
## Job Workflow
73+
74+
The job executes the following steps in sequence:
75+
76+
1. Stops the target EC2 instance
77+
2. Verifies instance state and performs validation:
78+
- Confirms instance has reached 'stopped' state
79+
- Validates new instance type is supported in the region
80+
3. Changes the instance type
81+
4. Optionally restarts the instance (based on `start-instance` option)
82+
83+
## Script Details
84+
85+
The job uses a combination of AWS CLI commands and a Bash script to:
86+
87+
1. Stop the instance safely
88+
2. Wait up to 30 seconds for instance to reach stopped state
89+
3. Verify the new instance type is supported in the region
90+
4. Modify the instance attribute to change the instance type
91+
5. Start the instance if requested
92+
93+
## Error Handling
94+
95+
The script includes several error checks:
96+
- Verifies instance reaches stopped state before proceeding
97+
- Validates instance type compatibility in the region
98+
- Confirms successful instance type modification
99+
- Exits with appropriate error codes and messages on failures
100+
101+
## Notes
102+
103+
- The job will not proceed with the instance type change if the instance fails to stop
104+
- If the change step fails, the instance will remain in a stopped state
105+
- The job supports cross-family instance type changes (e.g., t3 to m5)
106+
- Default node filtering is configured to target EC2 instances using the tag 'ec2', but you must pick the nodes at the time of execution.
107+
108+
## Troubleshooting
109+
110+
If you encounter issues:
111+
1. Verify the target instance is accessible and in a valid state
112+
2. Ensure the new instance type is supported in your region
113+
3. Check AWS credentials and permissions
114+
4. Review job logs for specific error messages

docs/learning/solutions/cost-management/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ PagerDuty provides a solution that helps users start automating diagnostics quic
1616

1717
| Examples |
1818
| --- |
19+
| <img src="/assets/img/aws-logo.png" width="30" height="30"> [AWS - Change EC2 Size](/learning/solutions/cost-management/aws-change-ec2-size.md) |
1920
| <img src="/assets/img/aws-logo.png" width="30" height="30"> [AWS - Identify Unused VPCs](/learning/solutions/cost-management/aws-list-unused-vpcs.md) |
2021
| <img src="/assets/img/aws-logo.png" width="30" height="30"> [AWS - Identify Unused Lambda Functions](/learning/solutions/cost-management/aws-list-unused-lambda.md) |
2122
| <img src="/assets/img/aws-logo.png" width="30" height="30"> [AWS - Identify Unused Security Groups](/learning/solutions/cost-management/aws-list-unused-securitygroups.md) |

0 commit comments

Comments
 (0)