feat(stepfunctions): add aws-sdk CloudFormation/EC2 and S3 PutObject integrations (#1556)

Step Functions could only invoke a few optimized/aws-sdk integrations
(Lambda, DynamoDB, SQS, nested state machines); any other resource failed
with 'Unsupported resource'. Provisioning state machines that drive
CloudFormation (StackSets), look up regions, or stage templates in S3 could
not run.

Add:
- a generic query-protocol bridge for arn:aws:states:::aws-sdk:cloudformation:*
  that flattens the task input to Query parameters, dispatches to the
  CloudFormation handler, and converts the XML response to the JSON shape the
  aws-sdk integration returns (member lists unwrapped to arrays);
- arn:aws:states:::aws-sdk:ec2:describeRegions;
- arn:aws:states:::s3:putObject (optimized and aws-sdk forms).

Tests: a unit test for the XML->JSON converter (scalars, nested objects,
member lists) and an integration test exercising ec2:describeRegions,
cloudformation:validateTemplate, and s3:putObject through Step Functions.
This commit is contained in:
Alex Banna authored and GitHub committed 2026-06-29 20:03:10 -05:00
1 parent f4c7a84de6
commit 677dfd6a16
5 files changed
+463 -1

No files matched your search

@@ -74,6 +74,9 @@ class AslExecutorCatchTest {
mock(DynamoDbService.class),
mock(DynamoDbJsonHandler.class),
mock(SqsJsonHandler.class),
mock(io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler.class),
mock(io.github.hectorvent.floci.services.ec2.Ec2Service.class),
mock(io.github.hectorvent.floci.services.s3.S3Service.class),
objectMapper,
new JsonataEvaluator(objectMapper),
mock(Instance.class));
@@ -0,0 +1,63 @@
package io.github.hectorvent.floci.services.stepfunctions;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
class QueryXmlToJsonTest {
private static final String NS = "http://cloudformation.amazonaws.com/doc/2010-05-15/";
private final ObjectMapper mapper = new ObjectMapper();
@Test
void scalarResultField() throws Exception {
String xml = "<CreateStackSetResponse xmlns=\"" + NS + "\">"
+ "<CreateStackSetResult><StackSetId>my-set:abc-123</StackSetId></CreateStackSetResult>"
+ "<ResponseMetadata><RequestId>r1</RequestId></ResponseMetadata></CreateStackSetResponse>";
JsonNode json = QueryXmlToJson.convert(xml, "CreateStackSetResult", mapper);
assertEquals("my-set:abc-123", json.path("StackSetId").asText());
}
@Test
void nestedObjectWithMemberLists() throws Exception {
String xml = "<DescribeStackSetResponse xmlns=\"" + NS + "\"><DescribeStackSetResult><StackSet>"
+ "<StackSetName>s</StackSetName><Status>ACTIVE</Status>"
+ "<Capabilities><member>CAPABILITY_IAM</member><member>CAPABILITY_NAMED_IAM</member></Capabilities>"
+ "<Parameters><member><ParameterKey>K</ParameterKey><ParameterValue>V</ParameterValue></member></Parameters>"
+ "</StackSet></DescribeStackSetResult></DescribeStackSetResponse>";
JsonNode json = QueryXmlToJson.convert(xml, "DescribeStackSetResult", mapper);
JsonNode ss = json.path("StackSet");
assertEquals("ACTIVE", ss.path("Status").asText());
assertTrue(ss.path("Capabilities").isArray());
assertEquals(2, ss.path("Capabilities").size());
assertEquals("CAPABILITY_IAM", ss.path("Capabilities").get(0).asText());
assertTrue(ss.path("Parameters").isArray());
assertEquals("K", ss.path("Parameters").get(0).path("ParameterKey").asText());
assertEquals("V", ss.path("Parameters").get(0).path("ParameterValue").asText());
}
@Test
void summariesMemberListBecomesArray() throws Exception {
String xml = "<ListStackInstancesResponse xmlns=\"" + NS + "\"><ListStackInstancesResult><Summaries>"
+ "<member><Account>111111111111</Account><Region>us-east-1</Region></member>"
+ "<member><Account>222222222222</Account><Region>us-east-1</Region></member>"
+ "</Summaries></ListStackInstancesResult></ListStackInstancesResponse>";
JsonNode json = QueryXmlToJson.convert(xml, "ListStackInstancesResult", mapper);
assertTrue(json.path("Summaries").isArray());
assertEquals(2, json.path("Summaries").size());
assertEquals("111111111111", json.path("Summaries").get(0).path("Account").asText());
assertEquals("us-east-1", json.path("Summaries").get(1).path("Region").asText());
}
@Test
void emptyResultWhenWrapperAbsent() throws Exception {
String xml = "<DeleteStackSetResponse xmlns=\"" + NS + "\">"
+ "<ResponseMetadata><RequestId>r</RequestId></ResponseMetadata></DeleteStackSetResponse>";
JsonNode json = QueryXmlToJson.convert(xml, "DeleteStackSetResult", mapper);
assertTrue(json.isObject());
assertTrue(json.isEmpty());
}
}
@@ -0,0 +1,136 @@
package io.github.hectorvent.floci.services.stepfunctions;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Exercises the Step Functions {@code aws-sdk:*} / optimized service integrations added for query and
* REST services: CloudFormation (query protocol bridged to JSON), EC2 DescribeRegions, and S3
* PutObject. These are the integrations DPS-style provisioning state machines rely on.
*/
@QuarkusTest
class StepFunctionsAwsSdkQueryIntegrationTest {
private static final String SFN_CONTENT_TYPE = "application/x-amz-json-1.0";
private static final String ROLE_ARN = "arn:aws:iam::000000000000:role/test-role";
private static final ObjectMapper mapper = new ObjectMapper();
@BeforeAll
static void configureRestAssured() {
RestAssuredJsonUtils.configureAwsContentTypes();
}
@Test
void ec2DescribeRegions_returnsRegionsArray() throws Exception {
String output = execute("ec2-regions", "arn:aws:states:::aws-sdk:ec2:describeRegions", "{}");
JsonNode result = mapper.readTree(output);
assertTrue(result.path("Regions").isArray(), "Regions should be an array");
assertFalse(result.path("Regions").isEmpty(), "Regions should be non-empty");
assertFalse(result.path("Regions").get(0).path("RegionName").asText().isBlank());
}
@Test
void cloudFormation_validateTemplate_dispatchesAndParses() throws Exception {
String params = """
{"TemplateBody": "{\\"Resources\\":{\\"Q\\":{\\"Type\\":\\"AWS::SQS::Queue\\"}}}"}
""";
// A successful execution proves the query-protocol bridge dispatched to CloudFormation and
// converted the XML response without error.
String output = execute("cfn-validate", "arn:aws:states:::aws-sdk:cloudformation:validateTemplate", params);
assertTrue(mapper.readTree(output).isObject());
}
@Test
void s3PutObject_storesObject() throws Exception {
String bucket = "sfn-s3-put-" + System.currentTimeMillis();
given().when().put("/" + bucket).then().statusCode(200);
String params = """
{"Bucket": "%s", "Key": "from-sfn.txt", "Body": "hello from step functions"}
""".formatted(bucket);
String output = execute("s3-put", "arn:aws:states:::s3:putObject", params);
assertTrue(mapper.readTree(output).has("ETag"), "PutObject result should carry an ETag");
// Confirm the object is actually retrievable.
given().when().get("/" + bucket + "/from-sfn.txt")
.then().statusCode(200).body(org.hamcrest.Matchers.containsString("hello from step functions"));
}
// ── helpers ─────────────────────────────────────────────────────────────
private String execute(String nameSuffix, String resource, String parameters) throws Exception {
String definition = """
{"StartAt":"Action","States":{"Action":{"Type":"Task","Resource":"%s","Parameters":%s,"End":true}}}
""".formatted(resource, parameters.strip());
String smArn = createStateMachine(nameSuffix + "-" + System.currentTimeMillis(), definition);
String execArn = startExecution(smArn);
return waitForExecution(execArn);
}
private String createStateMachine(String name, String definition) {
Response resp = given()
.header("X-Amz-Target", "AWSStepFunctions.CreateStateMachine")
.contentType(SFN_CONTENT_TYPE)
.body("""
{"name": "%s", "definition": %s, "roleArn": "%s"}
""".formatted(name, quote(definition), ROLE_ARN))
.when().post("/");
resp.then().statusCode(200);
return resp.jsonPath().getString("stateMachineArn");
}
private String startExecution(String smArn) {
Response resp = given()
.header("X-Amz-Target", "AWSStepFunctions.StartExecution")
.contentType(SFN_CONTENT_TYPE)
.body("""
{"stateMachineArn": "%s", "input": "{}"}
""".formatted(smArn))
.when().post("/");
resp.then().statusCode(200);
return resp.jsonPath().getString("executionArn");
}
private String waitForExecution(String execArn) throws InterruptedException {
for (int i = 0; i < 50; i++) {
Response resp = given()
.header("X-Amz-Target", "AWSStepFunctions.DescribeExecution")
.contentType(SFN_CONTENT_TYPE)
.body("""
{"executionArn": "%s"}
""".formatted(execArn))
.when().post("/");
String status = resp.jsonPath().getString("status");
if ("SUCCEEDED".equals(status)) {
return resp.jsonPath().getString("output");
}
if ("FAILED".equals(status) || "ABORTED".equals(status) || "TIMED_OUT".equals(status)) {
fail("Execution " + status + ": " + resp.body().asString());
}
Thread.sleep(100);
}
fail("Execution did not complete within timeout");
return null;
}
private static String quote(String raw) {
return "\"" + raw
.replace("\\", "\\\\")
.replace("\"", "\\\"")
.replace("\n", "\\n")
.replace("\r", "\\r")
.replace("\t", "\\t")
+ "\"";
}
}