fix(appconfig): honor the latest version number when creating hosted configurations (#10043)

Compare the optional locking token with the latest hosted version for the profile before storing a new configuration. Two callers that read the same version can no longer both complete conditional writes against it.

Co-authored-by: Andre Kurait <AndreKurait@gmail.com>
Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
Signed-off-by: Jackson Price <jxnprice@amazon.com>
This commit is contained in:
Jackson PriceandAndre Kurait authored and GitHub committed 2026-12-03 07:12:42 -04:00
1 parent 9c95135647
commit f16bd3787c
4 files changed
+73 -4

No files matched your search

@@ -105,6 +105,44 @@ class AppConfigTest {
assertThat(response.versionNumber()).isEqualTo(1);
}
@Test
@DisplayName("A hosted configuration write can require the latest version of its profile")
void conditionalHostedVersionCreateRejectsAnOutdatedVersion() {
String app = appConfig.createApplication(r -> r.name(TestFixtures.uniqueName("version-lock"))).id();
try {
String profile = appConfig.createConfigurationProfile(r -> r.applicationId(app)
.name("hosted").locationUri("hosted").type("AWS.Freeform")).id();
CreateHostedConfigurationVersionRequest request = CreateHostedConfigurationVersionRequest.builder()
.applicationId(app).configurationProfileId(profile).contentType("text/plain")
.content(SdkBytes.fromUtf8String("first")).build();
int first = appConfig.createHostedConfigurationVersion(request).versionNumber();
CreateHostedConfigurationVersionRequest update = request.toBuilder().latestVersionNumber(first)
.content(SdkBytes.fromUtf8String("second")).build();
int second = appConfig.createHostedConfigurationVersion(update).versionNumber();
ConflictException stale = assertThrows(ConflictException.class,
() -> appConfig.createHostedConfigurationVersion(update));
assertThat(stale.statusCode()).isEqualTo(409);
assertThat(stale.awsErrorDetails().errorMessage())
.isEqualTo("Expected latest version 1 does not match actual latest version 2");
assertThat(appConfig.getHostedConfigurationVersion(r -> r.applicationId(app)
.configurationProfileId(profile).versionNumber(second)).content().asUtf8String()).isEqualTo("second");
CreateHostedConfigurationVersionRequest malformed = request.toBuilder()
.overrideConfiguration(c -> c.putHeader("Latest-Version-Number", "invalid")).build();
AppConfigException invalid = assertThrows(AppConfigException.class,
() -> appConfig.createHostedConfigurationVersion(malformed));
assertThat(invalid.statusCode()).isEqualTo(400);
assertThat(invalid.awsErrorDetails().errorCode()).isEqualTo("BadRequestException");
int third = appConfig.createHostedConfigurationVersion(request.toBuilder()
.latestVersionNumber(second).content(SdkBytes.fromUtf8String("third")).build()).versionNumber();
assertThat(third).isEqualTo(second + 1);
} finally {
appConfig.deleteApplication(r -> r.applicationId(app));
}
}
@Test
@Order(5)
void createDeploymentStrategy() {