From 6b59009a058b2812dc6fc5cf704a65ff06c75e71 Mon Sep 17 00:00:00 2001 From: Marco Dinis Date: Thu, 16 May 2024 17:03:38 +0100 Subject: [PATCH] improve maxresults param --- lib/srv/server/ec2_watcher.go | 3 +++ lib/srv/server/ssm_install.go | 5 +---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/srv/server/ec2_watcher.go b/lib/srv/server/ec2_watcher.go index 3d2e7679d8dc0..c096393ac832c 100644 --- a/lib/srv/server/ec2_watcher.go +++ b/lib/srv/server/ec2_watcher.go @@ -272,6 +272,9 @@ const ( ) // awsEC2APIChunkSize is the max number of instances SSM will send commands to at a time +// This is used for limiting the number of instances for API Calls: +// ssm:SendCommand only accepts between 0 and 50. +// ssm:DescribeInstanceInformation only accepts between 5 and 50. const awsEC2APIChunkSize = 50 func newEC2InstanceFetcher(cfg ec2FetcherConfig) *ec2InstanceFetcher { diff --git a/lib/srv/server/ssm_install.go b/lib/srv/server/ssm_install.go index 137a8b0573c89..395a7c2874c1a 100644 --- a/lib/srv/server/ssm_install.go +++ b/lib/srv/server/ssm_install.go @@ -210,14 +210,11 @@ type instanceIDsSSMState struct { func (si *SSMInstaller) describeSSMAgentState(ctx context.Context, req SSMRunRequest, allInstanceIDs []string) (*instanceIDsSSMState, error) { ret := &instanceIDsSSMState{} - const defaultMaxResults = 10 - ssmInstancesInfo, err := req.SSM.DescribeInstanceInformationWithContext(ctx, &ssm.DescribeInstanceInformationInput{ Filters: []*ssm.InstanceInformationStringFilter{ {Key: aws.String(ssm.InstanceInformationFilterKeyInstanceIds), Values: aws.StringSlice(allInstanceIDs)}, }, - // AWS returns an error if MaxResults is less than 5. - MaxResults: aws.Int64(max(defaultMaxResults, int64(len(allInstanceIDs)))), + MaxResults: aws.Int64(awsEC2APIChunkSize), }) if err != nil { return nil, trace.Wrap(awslib.ConvertRequestFailureError(err))