Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

feat(cloudformation): provision Kinesis Firehose delivery streams (#1399)

Hector Ventura17d5bb84fa07
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java
index 9578acaaaf..2ecddeb9e0 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationResourceProvisioner.java
@@ -25,6 +25,8 @@ import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.services.kinesis.KinesisService;
import io.github.hectorvent.floci.services.ec2.model.Tag;
import io.github.hectorvent.floci.services.ecs.EcsService;
+import io.github.hectorvent.floci.services.firehose.FirehoseService;
+import io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription;
import io.github.hectorvent.floci.services.rds.RdsService;
import io.github.hectorvent.floci.services.eks.EksService;
import io.github.hectorvent.floci.services.eks.model.CreateClusterRequest;
@@ -148,6 +150,7 @@ public class CloudFormationResourceProvisioner {
private final KinesisService kinesisService;
private final CloudWatchMetricsService cloudWatchMetricsService;
private final AutoScalingService autoScalingService;
+ private final FirehoseService firehoseService;
@Inject
public CloudFormationResourceProvisioner(S3Service s3Service, SqsService sqsService,
@@ -175,7 +178,8 @@ public class CloudFormationResourceProvisioner {
CloudWatchLogsService logsService,
KinesisService kinesisService,
CloudWatchMetricsService cloudWatchMetricsService,
- AutoScalingService autoScalingService) {
+ AutoScalingService autoScalingService,
+ FirehoseService firehoseService) {
this.s3Service = s3Service;
this.sqsService = sqsService;
this.snsService = snsService;
@@ -206,6 +210,7 @@ public class CloudFormationResourceProvisioner {
this.kinesisService = kinesisService;
this.cloudWatchMetricsService = cloudWatchMetricsService;
this.autoScalingService = autoScalingService;
+ this.firehoseService = firehoseService;
}
/**
@@ -315,6 +320,8 @@ public class CloudFormationResourceProvisioner {
case "AWS::EC2::Route" -> provisionRoute(resource, properties, engine, region);
case "AWS::EC2::NatGateway" -> provisionNatGateway(resource, properties, engine, region);
case "AWS::EC2::EIP" -> provisionEip(resource, region);
+ case "AWS::KinesisFirehose::DeliveryStream" ->
+ provisionFirehoseDeliveryStream(resource, properties, engine, stackName);
case "AWS::EC2::Instance" -> provisionEc2Instance(resource, properties, engine, region);
// RDS. DBInstance/DBCluster start real RDS containers (same as the direct API).
case "AWS::RDS::DBSubnetGroup" -> provisionDbSubnetGroup(resource, properties, engine, stackName);
@@ -418,6 +425,7 @@ public class CloudFormationResourceProvisioner {
case "AWS::ElasticLoadBalancingV2::TargetGroup" -> elbV2Service.deleteTargetGroup(region, physicalId);
case "AWS::ElasticLoadBalancingV2::Listener" -> elbV2Service.deleteListener(region, physicalId);
case "AWS::ElasticLoadBalancingV2::ListenerRule" -> elbV2Service.deleteRule(region, physicalId);
+ case "AWS::KinesisFirehose::DeliveryStream" -> firehoseService.deleteDeliveryStream(physicalId);
case "AWS::EC2::Instance" -> ec2Service.terminateInstances(region, List.of(physicalId));
case "AWS::RDS::DBInstance" -> rdsService.deleteDbInstance(physicalId);
case "AWS::RDS::DBCluster" -> rdsService.deleteDbCluster(physicalId);
@@ -1040,6 +1048,48 @@ public class CloudFormationResourceProvisioner {
}
}
+ // ── Kinesis Data Firehose ───────────────────────────────────────────────────
+
+ private void provisionFirehoseDeliveryStream(StackResource r, JsonNode props,
+ CloudFormationTemplateEngine engine, String stackName) {
+ String name = resolveOptional(props, "DeliveryStreamName", engine);
+ if (name == null || name.isBlank()) {
+ name = generatePhysicalName(stackName, r.getLogicalId(), 64, false);
+ }
+
+ DeliveryStreamDescription.S3Destination s3 = null;
+ JsonNode s3Node = props != null && props.has("ExtendedS3DestinationConfiguration")
+ ? props.get("ExtendedS3DestinationConfiguration")
+ : (props != null ? props.get("S3DestinationConfiguration") : null);
+ if (s3Node != null && !s3Node.isNull()) {
+ s3 = new DeliveryStreamDescription.S3Destination();
+ s3.setBucketArn(blankToNull(engine.resolve(s3Node.path("BucketARN"))));
+ s3.setPrefix(blankToNull(engine.resolve(s3Node.path("Prefix"))));
+ if (s3Node.has("BufferingHints")) {
+ JsonNode hints = s3Node.get("BufferingHints");
+ var bufferingHints = new DeliveryStreamDescription.BufferingHints();
+ bufferingHints.setSizeInMBs(parseIntProp(hints, "SizeInMBs", engine, 5));
+ bufferingHints.setIntervalInSeconds(parseIntProp(hints, "IntervalInSeconds", engine, 300));
+ s3.setBufferingHints(bufferingHints);
+ }
+ }
+
+ List<DeliveryStreamDescription.Tag> tags = new ArrayList<>();
+ if (props != null && props.has("Tags") && props.get("Tags").isArray()) {
+ for (JsonNode tag : props.get("Tags")) {
+ String key = engine.resolve(tag.path("Key"));
+ if (!key.isEmpty()) {
+ tags.add(new DeliveryStreamDescription.Tag(key, engine.resolve(tag.path("Value"))));
+ }
+ }
+ }
+
+ String arn = firehoseService.createDeliveryStream(name, s3, tags);
+ // Ref returns the delivery stream name; Fn::GetAtt Arn returns the stream ARN.
+ r.setPhysicalId(name);
+ r.getAttributes().put("Arn", arn);
+ }
+
// ── SNS ───────────────────────────────────────────────────────────────────
private void provisionSnsTopic(StackResource r, JsonNode props, CloudFormationTemplateEngine engine,
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationFirehoseIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationFirehoseIntegrationTest.java
new file mode 100644
index 0000000000..a32a24b772
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationFirehoseIntegrationTest.java
@@ -0,0 +1,91 @@
+package io.github.hectorvent.floci.services.cloudformation;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.config.EncoderConfig;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.containsString;
+
+/**
+ * End-to-end check that CloudFormation provisions an AWS::KinesisFirehose::DeliveryStream for real
+ * (into FirehoseService) rather than stubbing it. Delivery streams are metadata (no container), so
+ * the test is Docker-free.
+ */
+@QuarkusTest
+class CloudFormationFirehoseIntegrationTest {
+
+ private static final String CFN_AUTH =
+ "AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/cloudformation/aws4_request";
+ private static final String FIREHOSE_AUTH =
+ "AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/firehose/aws4_request";
+
+ @Test
+ void createStackProvisionsDeliveryStreamVisibleToFirehose() {
+ String suffix = Long.toString(System.nanoTime(), 36);
+ String streamName = "cfn-firehose-" + suffix;
+ String stackName = "cfn-firehose-stack-" + suffix;
+
+ String template = """
+ {
+ "Resources": {
+ "Stream": {
+ "Type": "AWS::KinesisFirehose::DeliveryStream",
+ "Properties": {
+ "DeliveryStreamName": "%s",
+ "DeliveryStreamType": "DirectPut",
+ "S3DestinationConfiguration": {
+ "BucketARN": "arn:aws:s3:::my-firehose-bucket",
+ "RoleARN": "arn:aws:iam::000000000000:role/firehose-role",
+ "Prefix": "logs/"
+ }
+ }
+ }
+ },
+ "Outputs": {
+ "StreamArn": {"Value": {"Fn::GetAtt": ["Stream", "Arn"]}}
+ }
+ }
+ """.formatted(streamName);
+
+ given()
+ .contentType("application/x-www-form-urlencoded")
+ .header("Authorization", CFN_AUTH)
+ .formParam("Action", "CreateStack")
+ .formParam("StackName", stackName)
+ .formParam("TemplateBody", template)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+
+ // Stack completes and Fn::GetAtt(Stream, Arn) resolves to the real delivery stream ARN.
+ given()
+ .contentType("application/x-www-form-urlencoded")
+ .header("Authorization", CFN_AUTH)
+ .formParam("Action", "DescribeStacks")
+ .formParam("StackName", stackName)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"))
+ .body(containsString(":deliverystream/" + streamName));
+
+ // The delivery stream really exists in Firehose.
+ given()
+ .config(RestAssured.config().encoderConfig(EncoderConfig.encoderConfig()
+ .encodeContentTypeAs("application/x-amz-json-1.1", ContentType.TEXT)))
+ .header("Authorization", FIREHOSE_AUTH)
+ .header("X-Amz-Target", "Firehose_20150804.DescribeDeliveryStream")
+ .contentType("application/x-amz-json-1.1")
+ .body("{\"DeliveryStreamName\":\"" + streamName + "\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body(containsString(streamName));
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CustomResourceProvisionerTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CustomResourceProvisionerTest.java
index 4c1c42bf75..f435a15392 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CustomResourceProvisionerTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CustomResourceProvisionerTest.java
@@ -48,7 +48,7 @@ class CustomResourceProvisionerTest {
provisioner = new CloudFormationResourceProvisioner(
null, null, null, null, lambdaService, null, null, null, null, null,
- null, null, null, null, null, null, mapper, store, endpoint, null, null, null, null, null, null, null, null, null, null, null);
+ null, null, null, null, null, null, mapper, store, endpoint, null, null, null, null, null, null, null, null, null, null, null, null);
}
private CloudFormationTemplateEngine engine() {
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/RdsCfnProvisionerTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/RdsCfnProvisionerTest.java
index 2be3d5140e..03ce4e9b49 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/RdsCfnProvisionerTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/RdsCfnProvisionerTest.java
@@ -44,7 +44,7 @@ class RdsCfnProvisionerTest {
null, null, null, null, null, null,
mapper,
null, null, null, null, null, null, null,
- rdsService, null, null, null, null, null);
+ rdsService, null, null, null, null, null, null);
}
private CloudFormationTemplateEngine engine() {