From 3d3ab0023f892a0609bb6725e4b1c3184b4eed3e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?V=C5=A9=20Th=E1=BA=BF=20Huy?=
<31652864+vuthehuyht@users.noreply.github.com>
Date: Wed, 2 Sep 2026 21:29:19 +0700
Subject: [PATCH] fix(cloudfront): persist and echo LambdaFunctionAssociations
and FunctionAssociations (#2915)
* fix(cloudfront): persist and echo LambdaFunctionAssociations and FunctionAssociations
CreateDistribution accepted LambdaFunctionAssociations and then silently
dropped them: the parser never read the element and the serializer
hardcoded Quantity 0. A distribution meant to run a viewer-request
Lambda@Edge function ended up with no function attached and no error.
FunctionAssociations (CloudFront Functions) had the same bug, so it is
fixed in the same change.
- parseDefaultCacheBehavior + parseCacheBehaviors: read LambdaFunctionARN,
EventType, IncludeBody for Lambda and FunctionARN, EventType for
Functions into the existing model fields.
- xmlDefaultCacheBehavior + xmlCacheBehavior: replace the two hardcoded
blocks with xmlLambdaFunctionAssociations / xmlFunctionAssociations,
still emitting 0 when empty.
- Validate EventType: Lambda allows all four event types, Functions only
viewer-request and viewer-response; an empty ARN or an invalid
EventType returns 400 InvalidArgument.
Closes #2835
* fix(cloudfront): validate association Quantity and brace association parsers
Address review feedback on the LambdaFunctionAssociations / FunctionAssociations
round-trip:
- The parsers now read the declared for each association block.
A malformed value returns 400 InvalidArgument; a value that differs from
the number of items returns 400 InconsistentQuantities, matching the
existing TrustedKeyGroups handling, instead of being silently recomputed
on read-back. An omitted Quantity is still accepted.
- Add braces to every conditional in the new association parsing paths, per
the repository convention in AGENTS.md.
---
.../cloudfront/CloudFrontController.java | 266 +++++++++++++++++-
.../cloudfront/CloudFrontControllerTest.java | 155 ++++++++++
2 files changed, 417 insertions(+), 4 deletions(-)
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontController.java b/src/main/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontController.java
index 0380250075..e6e2450456 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontController.java
@@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.function.Function;
@Path("/2020-05-31")
@@ -1977,8 +1978,8 @@ public class CloudFrontController {
xml.raw(xmlQuantityItems("AllowedMethods", "Method", allowed.size(),
allowed.stream().map(m -> "" + XmlBuilder.escape(m) + "").toList()));
- xml.start("FunctionAssociations").elem("Quantity", 0).end("FunctionAssociations");
- xml.start("LambdaFunctionAssociations").elem("Quantity", 0).end("LambdaFunctionAssociations");
+ xml.raw(xmlFunctionAssociations(dcb.getFunctionAssociations()));
+ xml.raw(xmlLambdaFunctionAssociations(dcb.getLambdaFunctionAssociations()));
xml.end("DefaultCacheBehavior");
return xml.build();
@@ -2006,13 +2007,50 @@ public class CloudFrontController {
xml.raw(xmlQuantityItems("AllowedMethods", "Method", allowed.size(),
allowed.stream().map(m -> "" + XmlBuilder.escape(m) + "").toList()));
- xml.start("FunctionAssociations").elem("Quantity", 0).end("FunctionAssociations");
- xml.start("LambdaFunctionAssociations").elem("Quantity", 0).end("LambdaFunctionAssociations");
+ xml.raw(xmlFunctionAssociations(cb.getFunctionAssociations()));
+ xml.raw(xmlLambdaFunctionAssociations(cb.getLambdaFunctionAssociations()));
xml.end("CacheBehavior");
return xml.build();
}
+ private String xmlLambdaFunctionAssociations(List