Skip to content

Commit 6ac3675

Browse files
committed
fix: replace invalid MultiValueHeadersEnabled with TargetGroupAttributes for ALB TargetGroup
MultiValueHeadersEnabled is not a valid CloudFormation property on AWS::ElasticLoadBalancingV2::TargetGroup. Multi-value headers must be configured via TargetGroupAttributes with the key lambda.multi_value_headers.enabled. Changes: - CloudFormationWriter: emit TargetGroupAttributes array when MultiValueHeaders=true, remove it when false (instead of setting the non-existent MultiValueHeadersEnabled property) - albEvents.template snapshot: remove MultiValueHeadersEnabled=false, add TargetGroupAttributes for the multi-value-headers case - ALBEventsTests: update assertions to check TargetGroupAttributes existence instead of MultiValueHeadersEnabled - TestServerlessApp.ALB/serverless.template: remove stale MultiValueHeadersEnabled from both target groups
1 parent 7e84c5a commit 6ac3675

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed

Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Writers/CloudFormationWriter.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,26 @@ private void ProcessAlbApiAttribute(ILambdaFunctionSerializable lambdaFunction,
633633
_templateWriter.SetToken($"{tgPath}.Metadata.Tool", CREATION_TOOL);
634634
_templateWriter.SetToken($"{tgPath}.DependsOn", permissionName);
635635
_templateWriter.SetToken($"{tgPath}.Properties.TargetType", "lambda");
636-
_templateWriter.SetToken($"{tgPath}.Properties.MultiValueHeadersEnabled", att.MultiValueHeaders);
636+
637+
// MultiValueHeaders must be set via TargetGroupAttributes, not as a top-level property.
638+
// The CFN property "MultiValueHeadersEnabled" does not exist on AWS::ElasticLoadBalancingV2::TargetGroup.
639+
if (att.MultiValueHeaders)
640+
{
641+
_templateWriter.SetToken($"{tgPath}.Properties.TargetGroupAttributes",
642+
new List<Dictionary<string, string>>
643+
{
644+
new Dictionary<string, string>
645+
{
646+
{ "Key", "lambda.multi_value_headers.enabled" },
647+
{ "Value", "true" }
648+
}
649+
}, TokenType.List);
650+
}
651+
else
652+
{
653+
_templateWriter.RemoveToken($"{tgPath}.Properties.TargetGroupAttributes");
654+
}
655+
637656
_templateWriter.SetToken($"{tgPath}.Properties.Targets", new List<Dictionary<string, object>>
638657
{
639658
new Dictionary<string, object>

Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ServerlessTemplates/albEvents.template

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
"DependsOn": "ALBHelloWorldALBPermission",
4545
"Properties": {
4646
"TargetType": "lambda",
47-
"MultiValueHeadersEnabled": false,
4847
"Targets": [
4948
{
5049
"Id": {
@@ -124,7 +123,12 @@
124123
"DependsOn": "ALBWithOptionsALBPermission",
125124
"Properties": {
126125
"TargetType": "lambda",
127-
"MultiValueHeadersEnabled": true,
126+
"TargetGroupAttributes": [
127+
{
128+
"Key": "lambda.multi_value_headers.enabled",
129+
"Value": "true"
130+
}
131+
],
128132
"Targets": [
129133
{
130134
"Id": {

Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/WriterTests/ALBEventsTests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public void ALBApiAttribute_GeneratesTargetGroupListenerRuleAndPermission(CloudF
5656
Assert.Equal("Amazon.Lambda.Annotations", templateWriter.GetToken<string>("Resources.HelloWorldALBTargetGroup.Metadata.Tool"));
5757
Assert.Equal("HelloWorldALBPermission", templateWriter.GetToken<string>("Resources.HelloWorldALBTargetGroup.DependsOn"));
5858
Assert.Equal("lambda", templateWriter.GetToken<string>("Resources.HelloWorldALBTargetGroup.Properties.TargetType"));
59-
Assert.False(templateWriter.GetToken<bool>("Resources.HelloWorldALBTargetGroup.Properties.MultiValueHeadersEnabled"));
59+
// When MultiValueHeaders is false (default), no TargetGroupAttributes should be present
60+
Assert.False(templateWriter.Exists("Resources.HelloWorldALBTargetGroup.Properties.TargetGroupAttributes"));
6061

6162
// Verify ListenerRule resource
6263
Assert.True(templateWriter.Exists("Resources.HelloWorldALBListenerRule"));
@@ -99,7 +100,7 @@ public void ALBApiAttribute_WithTemplateReference_UsesRef(CloudFormationTemplate
99100
[Theory]
100101
[InlineData(CloudFormationTemplateFormat.Json)]
101102
[InlineData(CloudFormationTemplateFormat.Yaml)]
102-
public void ALBApiAttribute_WithMultiValueHeaders_SetsEnabled(CloudFormationTemplateFormat templateFormat)
103+
public void ALBApiAttribute_WithMultiValueHeaders_SetsTargetGroupAttributes(CloudFormationTemplateFormat templateFormat)
103104
{
104105
// ARRANGE
105106
var mockFileManager = GetMockFileManager(string.Empty);
@@ -122,7 +123,8 @@ public void ALBApiAttribute_WithMultiValueHeaders_SetsEnabled(CloudFormationTemp
122123

123124
// ASSERT
124125
templateWriter.Parse(mockFileManager.ReadAllText(ServerlessTemplateFilePath));
125-
Assert.True(templateWriter.GetToken<bool>("Resources.MyFunctionALBTargetGroup.Properties.MultiValueHeadersEnabled"));
126+
// When MultiValueHeaders is true, TargetGroupAttributes should contain the lambda.multi_value_headers.enabled attribute
127+
Assert.True(templateWriter.Exists("Resources.MyFunctionALBTargetGroup.Properties.TargetGroupAttributes"));
126128
}
127129

128130
[Theory]

Libraries/test/TestServerlessApp.ALB/serverless.template

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@
208208
"DependsOn": "ALBHelloALBPermission",
209209
"Properties": {
210210
"TargetType": "lambda",
211-
"MultiValueHeadersEnabled": false,
212211
"Targets": [
213212
{
214213
"Id": {
@@ -227,9 +226,6 @@
227226
"Tool": "Amazon.Lambda.Annotations"
228227
},
229228
"Properties": {
230-
"ListenerArn": {
231-
"Ref": "ALBTestListener"
232-
},
233229
"Priority": 1,
234230
"Conditions": [
235231
{
@@ -246,7 +242,10 @@
246242
"Ref": "ALBHelloALBTargetGroup"
247243
}
248244
}
249-
]
245+
],
246+
"ListenerArn": {
247+
"Ref": "ALBTestListener"
248+
}
250249
}
251250
},
252251
"ALBHealth": {
@@ -290,7 +289,6 @@
290289
"DependsOn": "ALBHealthALBPermission",
291290
"Properties": {
292291
"TargetType": "lambda",
293-
"MultiValueHeadersEnabled": false,
294292
"Targets": [
295293
{
296294
"Id": {
@@ -309,9 +307,6 @@
309307
"Tool": "Amazon.Lambda.Annotations"
310308
},
311309
"Properties": {
312-
"ListenerArn": {
313-
"Ref": "ALBTestListener"
314-
},
315310
"Priority": 2,
316311
"Conditions": [
317312
{
@@ -328,7 +323,10 @@
328323
"Ref": "ALBHealthALBTargetGroup"
329324
}
330325
}
331-
]
326+
],
327+
"ListenerArn": {
328+
"Ref": "ALBTestListener"
329+
}
332330
}
333331
}
334332
},

0 commit comments

Comments
 (0)