fix(sfn): enforce the alias and published version quotas per state machine (#3580)

CreateStateMachineAlias rejects the 101st alias, and publishing rejects the
1001st version, with ServiceQuotaExceededException.

* Fix #3575
* Fix #3614

Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
Matheus Oliveira authored and GitHub committed 2026-09-14 20:55:32 -04:00
1 parent d45a437122
commit 4707d4d3a8
3 files changed
+87

No files matched your search

@@ -555,6 +555,13 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
throw new AwsException(
"ConflictException", "State machine alias already exists: " + aliasArn, 409);
}
if (stateMachineAliasStore.scan(key -> key.startsWith(stateMachineArn + ":")).size()
>= MAX_ALIASES_PER_STATE_MACHINE) {
throw new AwsException("ServiceQuotaExceededException",
"The state machine already has the maximum of " + MAX_ALIASES_PER_STATE_MACHINE
+ " aliases.",
402);
}
StateMachineAlias alias = new StateMachineAlias();
alias.setStateMachineAliasArn(aliasArn);
@@ -1307,6 +1314,12 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
}
private StateMachineVersion addVersion(StateMachine stateMachine, String description) {
if (stateMachine.getVersions().size() >= MAX_VERSIONS_PER_STATE_MACHINE) {
throw new AwsException("ServiceQuotaExceededException",
"The state machine already has the maximum of " + MAX_VERSIONS_PER_STATE_MACHINE
+ " published versions.",
402);
}
int next = stateMachine.getVersionCounter() + 1;
stateMachine.setVersionCounter(next);
StateMachineVersion version = new StateMachineVersion(
@@ -1641,6 +1654,8 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
private static final int MAX_DEFINITION_LENGTH = 1_048_576;
private static final int MAX_ARN_LENGTH = 256;
private static final int MAX_VERSION_DESCRIPTION_LENGTH = 256;
private static final int MAX_VERSIONS_PER_STATE_MACHINE = 1000;
private static final int MAX_ALIASES_PER_STATE_MACHINE = 100;
private static final String INVALID_STATE_MACHINE_NAME_CHARACTERS =
"<>[]{}?*\"#%\\^|~`$&,;:/";
private static final Set<String> STATE_TYPES = Set.of(
@@ -190,4 +190,38 @@ class StepFunctionsAliasesIntegrationTest {
""".formatted(stateMachineArn))
.then().statusCode(400).body(containsString("ValidationException"));
}
@Test
void createAliasEnforcesTheQuotaOfOneHundredAliasesPerStateMachine() {
String name = "alias-quota-" + System.currentTimeMillis();
Response created = call("CreateStateMachine", """
{"name":"%s","definition":"%s",
"roleArn":"arn:aws:iam::000000000000:role/r","publish":true}
""".formatted(name, DEF));
String stateMachineArn = created.then().statusCode(200)
.extract().jsonPath().getString("stateMachineArn");
String versionArn = created.jsonPath().getString("stateMachineVersionArn");
String createAliasRequest = """
{"name":"%s","routingConfiguration":[
{"stateMachineVersionArn":"%s","weight":100}]}
""";
for (int i = 1; i <= 100; i++) {
call("CreateStateMachineAlias", createAliasRequest.formatted("Q-" + i, versionArn))
.then().statusCode(200);
}
call("CreateStateMachineAlias", createAliasRequest.formatted("Q-101", versionArn))
.then().statusCode(402)
.body(containsString("ServiceQuotaExceededException"));
call("CreateStateMachineAlias", createAliasRequest.formatted("Q-1", versionArn))
.then().statusCode(200)
.body("stateMachineAliasArn", is(stateMachineArn + ":Q-1"));
call("DeleteStateMachineAlias",
"{\"stateMachineAliasArn\":\"" + stateMachineArn + ":Q-1\"}")
.then().statusCode(200);
call("CreateStateMachineAlias", createAliasRequest.formatted("Q-101", versionArn))
.then().statusCode(200);
}
}
@@ -213,6 +213,44 @@ class StepFunctionsVersionsIntegrationTest {
.body(containsString("ConflictException"));
}
@Test
void publishEnforcesTheQuotaOfOneThousandVersionsPerStateMachine() {
String name = "ver-quota-" + System.currentTimeMillis();
String arn = call("CreateStateMachine",
"{\"name\":\"" + name + "\",\"definition\":\"" + DEF
+ "\",\"roleArn\":\"arn:aws:iam::000000000000:role/r0\",\"publish\":true}")
.then().statusCode(200)
.extract().jsonPath().getString("stateMachineArn");
for (int i = 2; i <= 1000; i++) {
call("UpdateStateMachine", "{\"stateMachineArn\":\"" + arn
+ "\",\"roleArn\":\"arn:aws:iam::000000000000:role/r" + i + "\",\"publish\":true}")
.then().statusCode(200);
}
call("PublishStateMachineVersion", "{\"stateMachineArn\":\"" + arn + "\"}")
.then().statusCode(200)
.body("stateMachineVersionArn", is(arn + ":1000"));
call("UpdateStateMachine", "{\"stateMachineArn\":\"" + arn
+ "\",\"roleArn\":\"arn:aws:iam::000000000000:role/over\",\"publish\":true}")
.then().statusCode(402)
.body(containsString("ServiceQuotaExceededException"));
call("DescribeStateMachine", "{\"stateMachineArn\":\"" + arn + "\"}")
.then().statusCode(200)
.body("roleArn", is("arn:aws:iam::000000000000:role/r1000"));
call("UpdateStateMachine", "{\"stateMachineArn\":\"" + arn
+ "\",\"roleArn\":\"arn:aws:iam::000000000000:role/unpublished\"}")
.then().statusCode(200);
call("PublishStateMachineVersion", "{\"stateMachineArn\":\"" + arn + "\"}")
.then().statusCode(402)
.body(containsString("ServiceQuotaExceededException"));
call("DeleteStateMachineVersion", "{\"stateMachineVersionArn\":\"" + arn + ":1\"}")
.then().statusCode(200);
call("PublishStateMachineVersion", "{\"stateMachineArn\":\"" + arn + "\"}")
.then().statusCode(200)
.body("stateMachineVersionArn", is(arn + ":1001"));
}
@Test
void invalidCreatePublishOptionsAndNamesAreRejectedBeforeStorage() {
String name = "ver-invalid-publish-" + System.currentTimeMillis();