fix(ssm): page GetParametersByPath and GetParameterHistory with MaxResults and NextToken (#6268)

* fix(ssm): page GetParametersByPath and GetParameterHistory with MaxResults and NextToken

Both actions ignored MaxResults and NextToken and returned every item.
Page them with Pagination.paginate, as DescribeParameters already does.

MaxResults is validated against the SSM model: 1-10 for
GetParametersByPath and 1-50 for GetParameterHistory, rejected with
ValidationException like DescribeParameters. A bad NextToken is
InvalidNextToken. Omitting MaxResults still returns everything, so
callers that never follow NextToken keep working.

History is paged by a zero-padded version cursor so version 10 sorts
after version 9.

Closes #6254

* fix(ssm): reject wrongly typed MaxResults and NextToken when paging parameters

A string MaxResults or a numeric NextToken was coerced instead of failing
to deserialize. Read both through the SSM deserialization helpers so they
fail with SerializationException, as other SSM fields do.

* fix(ssm): refuse a parameter page token minted for another listing

GetParametersByPath and GetParameterHistory tokens were bare cursors, so a
token from another operation, path or parameter was read as a position
in this listing and could skip results or return an empty page. Bind
each token to its operation, region and selection (path and Recursive,
or parameter name) and answer a mismatch with InvalidNextToken.

* test(ssm): follow GetParametersByPath and GetParameterHistory pages with SDK paginators

* fix(ssm): read pagination fields before listing parameters or their history

GetParameterHistory looked the parameter up before reading MaxResults and
NextToken, so a missing parameter answered ParameterNotFound for a request
whose pagination fields failed to deserialize or validate. Read and
validate both fields first in GetParameterHistory and GetParametersByPath.

* fix(ssm): refuse path and history page tokens in DescribeParameters

DescribeParameters decodes its token as a bare name cursor, so a
GetParametersByPath or GetParameterHistory token was read as a name and
could return a truncated or empty page. Refuse a token that decodes to
either namespace with InvalidNextToken. Its own tokens are unaffected:
the namespaces contain a colon, which AWS does not allow in a name.

* fix(ssm): bind parameter page tokens to the requesting account

Parameter storage is partitioned by account, but GetParametersByPath and
GetParameterHistory tokens named only the region and selection, so a token
minted in one account was accepted in another and skipped its entries.
Add the request account to both token namespaces.

* style(ssm): keep each javadoc on the method it describes

* fix(ssm): page DescribeParameters through the shared paging helpers

DescribeParameters repeated the MaxResults range check word for word and
decoded its token a second time to refuse GetParametersByPath and
GetParameterHistory tokens. Route it through pageRequest and page under a
namespace of its own, keeping its default page of 50. Its tokens are now
bound to the account and region like the other two listings, and a
wrongly typed MaxResults or NextToken fails to deserialize as theirs do.

Also cover resuming GetParametersByPath after the parameter that ended
the previous page is deleted.

---------

Co-authored-by: Priamo <pgermosen@gmail.com>
This commit is contained in:
Allen SanbornandPriamo authored and GitHub committed 2026-10-24 14:27:22 -04:00
1 parent 8d25cd91a6
commit 25a63eef9e
4 files changed
+361 -16

No files matched your search

@@ -42,6 +42,7 @@ import software.amazon.awssdk.services.ssm.model.UnlabelParameterVersionResponse
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static org.assertj.core.api.Assertions.*;
@@ -398,4 +399,32 @@ class SsmTest {
ssm.deleteParameter(DeleteParameterRequest.builder().name(name).build());
}
}
@Test
void paginatorsFollowNextTokenForPathAndHistory() {
String path = "/sdk-test/paging-" + UUID.randomUUID();
List<String> names = List.of(path + "/p1", path + "/p2", path + "/p3", path + "/p4", path + "/p5");
try {
names.forEach(name -> ssm.putParameter(PutParameterRequest.builder()
.name(name).value("v1").type(ParameterType.STRING).overwrite(true).build()));
for (int version = 2; version <= 3; version++) {
ssm.putParameter(PutParameterRequest.builder()
.name(names.get(0)).value("v" + version).type(ParameterType.STRING).overwrite(true).build());
}
List<GetParametersByPathResponse> pathPages = ssm.getParametersByPathPaginator(
GetParametersByPathRequest.builder().path(path).maxResults(2).build()).stream().toList();
assertThat(pathPages).hasSize(3).allSatisfy(page -> assertThat(page.parameters()).hasSizeLessThanOrEqualTo(2));
assertThat(pathPages.stream().flatMap(page -> page.parameters().stream()).map(p -> p.name()).toList())
.containsExactlyInAnyOrderElementsOf(names);
List<GetParameterHistoryResponse> historyPages = ssm.getParameterHistoryPaginator(
GetParameterHistoryRequest.builder().name(names.get(0)).maxResults(1).build()).stream().toList();
assertThat(historyPages).hasSize(3).allSatisfy(page -> assertThat(page.parameters()).hasSize(1));
assertThat(historyPages.stream().flatMap(page -> page.parameters().stream()).map(p -> p.version())
.toList()).containsExactly(1L, 2L, 3L);
} finally {
ssm.deleteParameters(DeleteParametersRequest.builder().names(names).build());
}
}
}