@@ -76,11 +76,17 @@ impl EcsService {
7676 . and_then ( |v| v. as_array ( ) )
7777 . cloned ( )
7878 . unwrap_or_default ( ) ;
79- let count = body
80- . get ( "count" )
81- . and_then ( |v| v. as_i64 ( ) )
82- . filter ( |n| ( 1 ..=10 ) . contains ( n) )
83- . unwrap_or ( 1 ) as usize ;
79+ // AWS caps RunTask at 1..=10 tasks per call and rejects anything else
80+ // with InvalidParameterException — it does NOT silently clamp to 1.
81+ let count = match body. get ( "count" ) . and_then ( |v| v. as_i64 ( ) ) {
82+ Some ( n) if ( 1 ..=10 ) . contains ( & n) => n as usize ,
83+ Some ( n) => {
84+ return Err ( invalid_parameter ( format ! (
85+ "count should be between 1 and 10, inclusive. count={n}"
86+ ) ) )
87+ }
88+ None => 1 ,
89+ } ;
8490 let group = opt_str ( & body, "group" ) . map ( String :: from) ;
8591 let started_by = opt_str ( & body, "startedBy" ) . map ( String :: from) ;
8692 let enable_execute_command = body
@@ -124,11 +130,13 @@ impl EcsService {
124130 let runtime = self . runtime . clone ( ) ;
125131 let mut accounts = self . state . write ( ) ;
126132 let state = accounts. get_or_create ( & account) ;
133+ // AWS rejects RunTask against a cluster that does not exist rather than
134+ // synthesizing one; a phantom cluster returns ClusterNotFoundException.
127135 let cluster_arn = state
128136 . clusters
129137 . get ( & cluster_name)
130138 . map ( |c| c. cluster_arn . clone ( ) )
131- . unwrap_or_else ( || state . cluster_arn ( & cluster_name) ) ;
139+ . ok_or_else ( || cluster_not_found ( & cluster_name) ) ? ;
132140 let ( _, family, rev) = resolve_task_definition_ref ( td_ref) ?;
133141 let revisions = state
134142 . task_definitions
@@ -579,6 +587,47 @@ mod multi_container_tests {
579587 }
580588 }
581589
590+ #[ test]
591+ fn run_task_count_over_ten_is_invalid_parameter ( ) {
592+ let svc = fresh_service ( ) ;
593+ // count is validated before the cluster/task-def are dereferenced.
594+ let err = match svc. run_task ( & make_request (
595+ "RunTask" ,
596+ json ! ( { "taskDefinition" : "x" , "count" : 50 } ) ,
597+ ) ) {
598+ Ok ( _) => panic ! ( "expected InvalidParameterException for count > 10" ) ,
599+ Err ( e) => e,
600+ } ;
601+ assert_eq ! ( err. code( ) , "InvalidParameterException" ) ;
602+ }
603+
604+ #[ test]
605+ fn create_service_negative_desired_count_is_invalid_parameter ( ) {
606+ let svc = fresh_service ( ) ;
607+ // desiredCount is validated before the cluster/task-def are resolved.
608+ let err = match svc. create_service ( & make_request (
609+ "CreateService" ,
610+ json ! ( { "serviceName" : "s" , "taskDefinition" : "x" , "desiredCount" : -3 } ) ,
611+ ) ) {
612+ Ok ( _) => panic ! ( "expected InvalidParameterException for negative desiredCount" ) ,
613+ Err ( e) => e,
614+ } ;
615+ assert_eq ! ( err. code( ) , "InvalidParameterException" ) ;
616+ }
617+
618+ #[ test]
619+ fn run_task_on_missing_cluster_is_cluster_not_found ( ) {
620+ let svc = fresh_service ( ) ;
621+ let err = match svc. run_task ( & make_request (
622+ "RunTask" ,
623+ json ! ( { "taskDefinition" : "x" , "cluster" : "ghost" , "count" : 1 } ) ,
624+ ) ) {
625+ Ok ( _) => panic ! ( "expected ClusterNotFoundException for a phantom cluster" ) ,
626+ Err ( e) => e,
627+ } ;
628+ assert_eq ! ( err. code( ) , "ClusterNotFoundException" ) ;
629+ }
630+
582631 #[ test]
583632 fn register_task_def_with_two_containers_then_run_task_starts_both ( ) {
584633 let svc = fresh_service ( ) ;
0 commit comments