Skip to content

Commit f24785f

Browse files
committed
CHECKENV_AWS_FETCH_LOOP_LIMIT to prevent fetching AWS too many params
1 parent c6419e1 commit f24785f

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

aws_ssm/parameters.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"fmt"
66
"log"
7+
"os"
8+
"strconv"
79
"strings"
810

911
"github.com/aws/aws-sdk-go-v2/service/ssm"
@@ -58,6 +60,21 @@ func FetchKeysOfParameters(
5860
MaxResults: 10,
5961
ParameterFilters: parameterFilters,
6062
}
63+
64+
// CHECKENV_AWS_FETCH_LOOP_LIMIT by default set to 10,
65+
// it is allows to load 100 parameters from AWS and it is
66+
// a limiter to prevent loading too many parameters without
67+
// control during passing erroneous filters
68+
var err error
69+
var fetchLoopLimit int
70+
fetchLoopLimitStr := os.Getenv("CHECKENV_AWS_FETCH_LOOP_LIMIT")
71+
if fetchLoopLimitStr != "" {
72+
fetchLoopLimit, err = strconv.Atoi(fetchLoopLimitStr)
73+
}
74+
if fetchLoopLimitStr == "" || err != nil {
75+
fetchLoopLimit = 10
76+
}
77+
6178
n := 0
6279
for {
6380
// Fetch list of parameter keys
@@ -76,7 +93,7 @@ func FetchKeysOfParameters(
7693
describeInput.NextToken = results.NextToken
7794

7895
n++
79-
if n >= 50 {
96+
if n >= fetchLoopLimit {
8097
log.Fatal("To many iterations over DescribeParameters loop")
8198
}
8299
}

0 commit comments

Comments
 (0)