Skip to content

Commit

Permalink
improve maxresults param
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoandredinis committed May 16, 2024
1 parent ca3da6f commit 6b59009
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/srv/server/ec2_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions lib/srv/server/ssm_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 6b59009

Please sign in to comment.