Commit 94c4e12
fix(scale-up): Add ec2:TerminateInstances permission to scale-up Lambda IAM policy (#5152)
## Description
The scale-up Lambda calls `terminateRunner(instanceId)` when JIT
configuration fails, but lacks the `ec2:TerminateInstances` IAM
permission. This leaves orphaned EC2 instances running when JIT setup
errors occur.
Adds `ec2:TerminateInstances` to
`modules/runners/policies/lambda-scale-up.json`, scoped with two
condition statements matching the pattern used in the scale-down Lambda
policy:
1. Scoped by `ghr:Application` tag (hardcoded value applied at instance
creation):
```json
{
"Effect": "Allow",
"Action": ["ec2:TerminateInstances"],
"Resource": ["*"],
"Condition": {
"StringEquals": {
"ec2:ResourceTag/ghr:Application": "github-action-runner"
}
}
}
```
2. Scoped by `gh:environment` tag (environment-specific):
```json
{
"Effect": "Allow",
"Action": ["ec2:TerminateInstances"],
"Resource": ["*"],
"Condition": {
"StringEquals": {
"ec2:ResourceTag/gh:environment": "${environment}"
}
}
}
```
Also passes the `environment` variable (`var.prefix`) to the policy
template in `scale-up.tf`.
## Test Plan
- Verified the policy JSON is valid and follows the existing conditional
scoping pattern from `lambda-scale-down.json`
- Both tag-based conditions (`ghr:Application` and `gh:environment`)
match the scale-down policy exactly
- The `environment` template variable is passed as `var.prefix`,
consistent with how scale-down passes it
## Related Issues
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: github-aws-runners-pr|bot <github-aws-runners-pr[bot]@users.noreply.github.com>1 parent a6af4d2 commit 94c4e12
2 files changed
Lines changed: 29 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
17 | 45 | | |
18 | 46 | | |
19 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| 124 | + | |
124 | 125 | | |
125 | 126 | | |
126 | 127 | | |
| |||
0 commit comments