Skip to content

Commit e388057

Browse files
committed
feat: Support RuntimeManagementConfig
1 parent 5324ec0 commit e388057

15 files changed

+1101
-2
lines changed

.cfnlintrc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ ignore_templates:
114114
- tests/translator/output/**/state_machine_with_event_schedule_state.json
115115
- tests/translator/output/**/state_machine_with_schedule.json
116116
- tests/translator/output/**/state_machine_with_schedule_dlq_retry_policy.json
117+
- tests/translator/output/**/globals_for_function.json # RuntimeManagementConfig
118+
- tests/translator/output/**/function_with_runtime_config.json # RuntimeManagementConfig
117119
ignore_checks:
118120
- E2531 # Deprecated runtime; not relevant for transform tests
119121
- W2531 # EOL runtime; not relevant for transform tests

docs/globals.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Currently, the following resources and properties are being supported:
7373
EventInvokeConfig:
7474
Architectures:
7575
EphemeralStorage:
76+
RuntimeManagementConfig:
7677
7778
Api:
7879
# Properties of AWS::Serverless::Api

samtranslator/model/lambda_.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class LambdaFunction(Resource):
3131
"Architectures": PropertyType(False, list_of(one_of(IS_STR, IS_DICT))),
3232
"SnapStart": PropertyType(False, IS_DICT),
3333
"EphemeralStorage": PropertyType(False, IS_DICT),
34+
"RuntimeManagementConfig": PropertyType(False, IS_DICT),
3435
}
3536

3637
Code: Dict[str, Any]
@@ -56,6 +57,7 @@ class LambdaFunction(Resource):
5657
Architectures: Optional[List[Any]]
5758
SnapStart: Optional[Dict[str, Any]]
5859
EphemeralStorage: Optional[Dict[str, Any]]
60+
RuntimeManagementConfig: Optional[Dict[str, Any]]
5961

6062
runtime_attrs = {"name": lambda self: ref(self.logical_id), "arn": lambda self: fnGetAtt(self.logical_id, "Arn")}
6163

@@ -66,6 +68,7 @@ class LambdaVersion(Resource):
6668
"CodeSha256": PropertyType(False, IS_STR),
6769
"Description": PropertyType(False, IS_STR),
6870
"FunctionName": PropertyType(True, one_of(IS_STR, IS_DICT)),
71+
"RuntimeManagementConfig": PropertyType(False, IS_DICT),
6972
}
7073

7174
runtime_attrs = {

samtranslator/model/sam_resources.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class SamFunction(SamResourceMacro):
127127
"Architectures": PropertyType(False, list_of(one_of(IS_STR, IS_DICT))),
128128
"SnapStart": PropertyType(False, IS_DICT),
129129
"FunctionUrlConfig": PropertyType(False, IS_DICT),
130+
"RuntimeManagementConfig": PropertyType(False, IS_DICT),
130131
}
131132

132133
FunctionName: Optional[Intrinsicable[str]]
@@ -530,6 +531,7 @@ def _construct_lambda_function(self) -> LambdaFunction:
530531

531532
lambda_function.CodeSigningConfigArn = self.CodeSigningConfigArn
532533

534+
lambda_function.RuntimeManagementConfig = self.RuntimeManagementConfig # type: ignore[attr-defined]
533535
self._validate_package_type(lambda_function)
534536
self._validate_architectures(lambda_function)
535537
return lambda_function
@@ -893,6 +895,8 @@ def _construct_version(
893895
lambda_version = LambdaVersion(logical_id=logical_id, attributes=attributes)
894896
lambda_version.FunctionName = function.get_runtime_attr("name")
895897
lambda_version.Description = self.VersionDescription
898+
# Copy the same runtime policy for the version and the function
899+
lambda_version.RuntimeManagementConfig = function.RuntimeManagementConfig
896900

897901
return lambda_version
898902

samtranslator/plugins/globals/globals.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict, List
1+
from typing import Dict, List
22

33
from samtranslator.model.exceptions import ExceptionWithMessage
44
from samtranslator.public.sdk.resource import SamResourceType
@@ -49,6 +49,7 @@ class Globals(object):
4949
"SnapStart",
5050
"EphemeralStorage",
5151
"FunctionUrlConfig",
52+
"RuntimeManagementConfig",
5253
],
5354
# Everything except
5455
# DefinitionBody: because its hard to reason about merge of Swagger dictionaries
@@ -88,7 +89,7 @@ class Globals(object):
8889
}
8990
# unreleased_properties *must be* part of supported_properties too
9091
unreleased_properties: Dict[str, List[str]] = {
91-
SamResourceType.Function.value: [],
92+
SamResourceType.Function.value: ["RuntimeManagementConfig"],
9293
}
9394

9495
def __init__(self, template): # type: ignore[no-untyped-def]

samtranslator/schema/aws_serverless_function.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ class ScheduleV2Event(BaseModel):
445445
Architectures = Optional[PassThrough]
446446
EphemeralStorage = Optional[PassThrough]
447447
SnapStart = Optional[PassThrough] # TODO: check the type
448+
RuntimeManagementConfig = Optional[PassThrough] # TODO: check the type
448449

449450

450451
class Properties(BaseModel):
@@ -504,6 +505,7 @@ class Properties(BaseModel):
504505
Role: Optional[SamIntrinsicable[str]] = prop("Role")
505506
Runtime: Optional[Runtime] = prop("Runtime")
506507
SnapStart: Optional[SnapStart] # TODO: add prop and types
508+
RuntimeManagementConfig: Optional[RuntimeManagementConfig] # TODO: add prop and types
507509
Tags: Optional[Tags] = prop("Tags")
508510
Timeout: Optional[Timeout] = prop("Timeout")
509511
Tracing: Optional[Tracing] = prop("Tracing")
@@ -536,6 +538,7 @@ class Globals(BaseModel):
536538
Architectures: Optional[Architectures] = prop("Architectures")
537539
EphemeralStorage: Optional[EphemeralStorage] = prop("EphemeralStorage")
538540
SnapStart: Optional[SnapStart] # TODO: add prop
541+
RuntimeManagementConfig: Optional[RuntimeManagementConfig] # TODO: add prop
539542

540543

541544
class Resource(BaseModel):

samtranslator/schema/schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,9 @@
532532
},
533533
"SnapStart": {
534534
"title": "Snapstart"
535+
},
536+
"RuntimeManagementConfig": {
537+
"title": "Runtimemanagementconfig"
535538
}
536539
},
537540
"additionalProperties": false
@@ -4002,6 +4005,9 @@
40024005
"SnapStart": {
40034006
"title": "Snapstart"
40044007
},
4008+
"RuntimeManagementConfig": {
4009+
"title": "Runtimemanagementconfig"
4010+
},
40054011
"Tags": {
40064012
"title": "Tags",
40074013
"description": "A map \\(string to string\\) that specifies the tags added to this function\\. For details about valid keys and values for tags, see [Tag Key and Value Requirements](https://docs.aws.amazon.com/lambda/latest/dg/configuration-tags.html#configuration-tags-restrictions) in the *AWS Lambda Developer Guide*\\. \nWhen the stack is created, AWS SAM automatically adds a `lambda:createdBy:SAM` tag to this Lambda function, and to the default roles that are generated for this function\\. \n*Type*: Map \n*Required*: No \n*AWS CloudFormation compatibility*: This property is similar to the [`Tags`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-tags) property of an `AWS::Lambda::Function` resource\\. The `Tags` property in AWS SAM consists of key\\-value pairs \\(whereas in AWS CloudFormation this property consists of a list of `Tag` objects\\)\\. Also, AWS SAM automatically adds a `lambda:createdBy:SAM` tag to this Lambda function, and to the default roles that are generated for this function\\.",
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
%YAML 1.1
2+
---
3+
Parameters:
4+
RuntimeVersionParam:
5+
Type: String
6+
RuntimeUpdateParam:
7+
Type: String
8+
9+
Resources:
10+
FunctionWithRuntimeManagementConfig:
11+
Type: AWS::Serverless::Function
12+
Properties:
13+
CodeUri: s3://sam-demo-bucket/hello.zip
14+
Handler: hello.handler
15+
Runtime: python3.8
16+
RuntimeManagementConfig:
17+
UpdateRuntimeOn: Auto
18+
MinimalFunctionWithManualRuntimeManagementConfig:
19+
Type: AWS::Serverless::Function
20+
Properties:
21+
CodeUri: s3://sam-demo-bucket/hello.zip
22+
Handler: hello.handler
23+
Runtime: python3.8
24+
RuntimeManagementConfig:
25+
UpdateRuntimeOn: Manual
26+
RuntimeVersionArn: !Sub arn:aws:lambda:${AWS::Region}::runtime:python3.8::0af1966588ced06e3143ae720245c9b7aeaae213c6921c12c742a166679cc505
27+
FunctionWithRuntimeManagementConfigAndAlias:
28+
Type: AWS::Serverless::Function
29+
Properties:
30+
CodeUri: s3://sam-demo-bucket/hello.zip
31+
Handler: hello.handler
32+
Runtime: python3.8
33+
AutoPublishAlias: live
34+
RuntimeManagementConfig:
35+
UpdateRuntimeOn: Auto
36+
FunctionWithIntrinsicUpdateRuntimeOn:
37+
Type: AWS::Serverless::Function
38+
Properties:
39+
CodeUri: s3://sam-demo-bucket/hello.zip
40+
Handler: hello.handler
41+
Runtime: python3.8
42+
RuntimeManagementConfig:
43+
UpdateRuntimeOn: !Ref RuntimeUpdateParam
44+
FunctionWithIntrinsicRuntimeVersion:
45+
Type: AWS::Serverless::Function
46+
Properties:
47+
CodeUri: s3://sam-demo-bucket/hello.zip
48+
Handler: hello.handler
49+
Runtime: python3.8
50+
RuntimeManagementConfig:
51+
UpdateRuntimeOn: !Ref RuntimeUpdateParam
52+
RuntimeVersionArn: !Ref RuntimeVersionParam

tests/translator/input/globals_for_function.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Globals:
2828
ApplyOn: PublishedVersions
2929
EphemeralStorage:
3030
Size: 1024
31+
RuntimeManagementConfig:
32+
UpdateRuntimeOn: Auto
3133

3234
Resources:
3335
MinimalFunction:
@@ -57,3 +59,5 @@ Resources:
5759
SnapStart:
5860
ApplyOn: None
5961
ReservedConcurrentExecutions: 100
62+
RuntimeManagementConfig:
63+
UpdateRuntimeOn: FunctionChange

0 commit comments

Comments
 (0)