Skip to content

Commit d7dd925

Browse files
committed
feat: Support InvokeMode in lambda function URL config
1 parent 8814f6a commit d7dd925

18 files changed

+61
-1
lines changed

samtranslator/internal/schema_source/aws_serverless_function.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class SNSEvent(BaseModel):
153153
class FunctionUrlConfig(BaseModel):
154154
AuthType: SamIntrinsicable[str] = functionurlconfig("AuthType")
155155
Cors: Optional[PassThroughProp] = functionurlconfig("Cors")
156+
InvokeMode: Optional[PassThroughProp] # TODO: add to doc
156157

157158

158159
class KinesisEventProperties(BaseModel):

samtranslator/model/lambda_.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,5 @@ class LambdaUrl(Resource):
174174
"TargetFunctionArn": GeneratedProperty(),
175175
"AuthType": GeneratedProperty(),
176176
"Cors": GeneratedProperty(),
177+
"InvokeMode": GeneratedProperty(),
177178
}

samtranslator/model/sam_resources.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,7 @@ def _construct_function_url(
10431043
lambda_url.TargetFunctionArn = (
10441044
lambda_alias.get_runtime_attr("arn") if lambda_alias else lambda_function.get_runtime_attr("name")
10451045
)
1046+
lambda_url.InvokeMode = function_url_config.get("InvokeMode")
10461047
return lambda_url
10471048

10481049
def _validate_function_url_params(

samtranslator/schema/schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197034,6 +197034,9 @@
197034197034
"description": "The Cross\\-Origin Resource Sharing \\(CORS\\) settings for your function URL\\. \n*Type*: [Cors](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-url-cors.html) \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`Cors`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-url-cors.html) property of an `AWS::Lambda::Url` resource\\.",
197035197035
"markdownDescription": "The Cross\\-Origin Resource Sharing \\(CORS\\) settings for your function URL\\. \n*Type*: [Cors](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-url-cors.html) \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`Cors`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-url-cors.html) property of an `AWS::Lambda::Url` resource\\.",
197036197036
"title": "Cors"
197037+
},
197038+
"InvokeMode": {
197039+
"$ref": "#/definitions/PassThroughProp"
197037197040
}
197038197041
},
197039197042
"required": [

schema_source/sam.schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,9 @@
12171217
"description": "The Cross\\-Origin Resource Sharing \\(CORS\\) settings for your function URL\\. \n*Type*: [Cors](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-url-cors.html) \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`Cors`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-url-cors.html) property of an `AWS::Lambda::Url` resource\\.",
12181218
"markdownDescription": "The Cross\\-Origin Resource Sharing \\(CORS\\) settings for your function URL\\. \n*Type*: [Cors](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-url-cors.html) \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`Cors`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-url-cors.html) property of an `AWS::Lambda::Url` resource\\.",
12191219
"title": "Cors"
1220+
},
1221+
"InvokeMode": {
1222+
"$ref": "#/definitions/PassThroughProp"
12201223
}
12211224
},
12221225
"required": [

tests/model/test_sam_resources.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,11 @@ def test_validate_function_url_config_properties_with_intrinsic(self):
475475
function.CodeUri = "s3://foobar/foo.zip"
476476
function.Runtime = "foo"
477477
function.Handler = "bar"
478-
function.FunctionUrlConfig = {"AuthType": {"Ref": "AWS_IAM"}, "Cors": {"Ref": "MyCorConfigRef"}}
478+
function.FunctionUrlConfig = {
479+
"AuthType": {"Ref": "AWS_IAM"},
480+
"Cors": {"Ref": "MyCorConfigRef"},
481+
"InvokeMode": {"Ref": "MyInvokeMode"},
482+
}
479483

480484
cfnResources = function.to_cloudformation(**self.kwargs)
481485
generatedUrlList = [x for x in cfnResources if isinstance(x, LambdaUrl)]
@@ -484,6 +488,7 @@ def test_validate_function_url_config_properties_with_intrinsic(self):
484488
self.assertEqual(generatedUrlList.__len__(), 1)
485489
self.assertEqual(generatedUrlList[0].AuthType, {"Ref": "AWS_IAM"})
486490
self.assertEqual(generatedUrlList[0].Cors, {"Ref": "MyCorConfigRef"})
491+
self.assertEqual(generatedUrlList[0].InvokeMode, {"Ref": "MyInvokeMode"})
487492

488493
@patch("boto3.session.Session.region_name", "ap-southeast-1")
489494
def test_with_valid_function_url_config(self):
@@ -594,6 +599,18 @@ def test_with_invalid_function_url_config_with_authorization_type_value_as_None(
594599
+ "`FunctionUrlConfig`. Please provide either AWS_IAM or NONE.",
595600
)
596601

602+
def test_with_function_url_config_with_invoke_mode(self):
603+
function = SamFunction("foo")
604+
function.CodeUri = "s3://foobar/foo.zip"
605+
function.Runtime = "foo"
606+
function.Handler = "bar"
607+
function.FunctionUrlConfig = {"AuthType": "AWS_IAM", "InvokeMode": "RESPONSE_STREAM"}
608+
cfnResources = function.to_cloudformation(**self.kwargs)
609+
generatedUrlList = [x for x in cfnResources if isinstance(x, LambdaUrl)]
610+
self.assertEqual(generatedUrlList.__len__(), 1)
611+
self.assertEqual(generatedUrlList[0].AuthType, "AWS_IAM")
612+
self.assertEqual(generatedUrlList[0].InvokeMode, "RESPONSE_STREAM")
613+
597614

598615
class TestInvalidSamConnectors(TestCase):
599616
kwargs = {

tests/translator/input/function_with_function_url_config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ Resources:
2626
ExposeHeaders:
2727
- x-amzn-header
2828
MaxAge: 10
29+
InvokeMode: RESPONSE_STREAM

tests/translator/input/function_with_function_url_config_and_autopublishalias.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ Resources:
2727
ExposeHeaders:
2828
- x-amzn-header
2929
MaxAge: 10
30+
InvokeMode: RESPONSE_STREAM

tests/translator/input/function_with_function_url_config_with_intrinsics.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ Parameters:
1212
Type: CommaDelimitedList
1313
Default: GET
1414

15+
InvokeModeRef:
16+
Type: String
17+
Default: BUFFERED
18+
1519
Resources:
1620
MyFunction:
1721
Type: AWS::Serverless::Function
@@ -27,3 +31,4 @@ Resources:
2731
Cors:
2832
AllowOrigins: !Ref AllowOriginsRef
2933
AllowMethods: !Ref AllowMethodsRef
34+
InvokeMode: !Ref InvokeModeRef

tests/translator/output/aws-cn/function_with_function_url_config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
],
8181
"MaxAge": 10
8282
},
83+
"InvokeMode": "RESPONSE_STREAM",
8384
"TargetFunctionArn": {
8485
"Ref": "MyFunction"
8586
}

0 commit comments

Comments
 (0)