Skip to content

Commit 7d951e1

Browse files
committed
fix: address code review comments on RunInstances validation
- Document maxRunInstancesBatchCount rationale (matches AWS EC2 default) - Add MaxCount validation with same checks as MinCount
1 parent 7850a05 commit 7d951e1

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

internal/services/ec2/provider.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import (
1818
)
1919

2020
const (
21-
defaultAccountID = plugin.DefaultAccountID
21+
defaultAccountID = plugin.DefaultAccountID
22+
// maxRunInstancesBatchCount matches the AWS EC2 default on-demand instance limit per launch request.
2223
maxRunInstancesBatchCount = 1000
2324
)
2425

@@ -203,6 +204,19 @@ func (p *Provider) handleRunInstances(form url.Values) (*plugin.Response, error)
203204
}
204205
count = n
205206
}
207+
if s := form.Get("MaxCount"); s != "" {
208+
n, err := strconv.Atoi(s)
209+
if err != nil || n <= 0 {
210+
return ec2XMLError("InvalidParameterValue", "MaxCount must be a positive integer", http.StatusBadRequest), nil
211+
}
212+
if n > maxRunInstancesBatchCount {
213+
return ec2XMLError("InvalidParameterValue", fmt.Sprintf("MaxCount exceeds maximum allowed value (%d)", maxRunInstancesBatchCount), http.StatusBadRequest), nil
214+
}
215+
if n < count {
216+
return ec2XMLError("InvalidParameterValue", "MaxCount must be greater than or equal to MinCount", http.StatusBadRequest), nil
217+
}
218+
count = n
219+
}
206220

207221
instances, err := p.store.RunInstances(defaultAccountID, imageID, instanceType, count)
208222
if err != nil {

0 commit comments

Comments
 (0)