Skip to content

Commit 030f794

Browse files
committed
feat: add support for Durable Functions
1 parent fc6bf17 commit 030f794

20 files changed

+839
-0
lines changed

.cfnlintrc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ ignore_templates:
148148
- tests/translator/output/**/function_with_tenancy_and_api_event.json # cfnlint is not updated to recognize the TenancyConfig property
149149
- tests/translator/output/**/function_with_tenancy_and_httpapi_event.json # cfnlint is not updated to recognize the TenancyConfig property
150150
- tests/translator/output/**/function_with_tenancy_config_global.json # cfnlint is not updated to recognize the TenancyConfig property
151+
- tests/translator/output/**/*durable_config*.json # TODO: Remove this once Durable Function is launched in CFN
151152

152153
ignore_checks:
153154
- E2531 # Deprecated runtime; not relevant for transform tests

samtranslator/internal/schema_source/aws_serverless_function.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ class Properties(BaseModel):
662662
RecursiveLoop: Optional[PassThroughProp] # TODO: add documentation
663663
SourceKMSKeyArn: Optional[PassThroughProp] # TODO: add documentation
664664
TenancyConfig: Optional[PassThroughProp] # TODO: add documentation
665+
DurableConfig: Optional[PassThroughProp] # TODO: add documentation
665666

666667

667668
class Globals(BaseModel):
@@ -723,6 +724,7 @@ class Globals(BaseModel):
723724
RecursiveLoop: Optional[PassThroughProp] # TODO: add documentation
724725
SourceKMSKeyArn: Optional[PassThroughProp] # TODO: add documentation
725726
TenancyConfig: Optional[PassThroughProp] # TODO: add documentation
727+
DurableConfig: Optional[PassThroughProp] # TODO: add documentation
726728

727729

728730
class Resource(ResourceAttributes):

samtranslator/model/lambda_.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class LambdaFunction(Resource):
3737
"LoggingConfig": GeneratedProperty(),
3838
"RecursiveLoop": GeneratedProperty(),
3939
"TenancyConfig": GeneratedProperty(),
40+
"DurableConfig": GeneratedProperty(),
4041
}
4142

4243
Code: Dict[str, Any]
@@ -66,6 +67,7 @@ class LambdaFunction(Resource):
6667
LoggingConfig: Optional[Dict[str, Any]]
6768
RecursiveLoop: Optional[str]
6869
TenancyConfig: Optional[Dict[str, Any]]
70+
DurableConfig: Optional[Dict[str, Any]]
6971

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

samtranslator/model/sam_resources.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ class SamFunction(SamResourceMacro):
185185
"RecursiveLoop": PassThroughProperty(False),
186186
"SourceKMSKeyArn": PassThroughProperty(False),
187187
"TenancyConfig": PassThroughProperty(False),
188+
"DurableConfig": PropertyType(False, IS_DICT),
188189
}
189190

190191
FunctionName: Optional[Intrinsicable[str]]
@@ -230,6 +231,7 @@ class SamFunction(SamResourceMacro):
230231
RecursiveLoop: Optional[str]
231232
SourceKMSKeyArn: Optional[str]
232233
TenancyConfig: Optional[Dict[str, Any]]
234+
DurableConfig: Optional[Dict[str, Any]]
233235

234236
event_resolver = ResourceTypeResolver(
235237
samtranslator.model.eventsources,
@@ -655,6 +657,7 @@ def _construct_lambda_function(self, intrinsics_resolver: IntrinsicsResolver) ->
655657
lambda_function.LoggingConfig = self.LoggingConfig
656658
lambda_function.TenancyConfig = self.TenancyConfig
657659
lambda_function.RecursiveLoop = self.RecursiveLoop
660+
lambda_function.DurableConfig = self.DurableConfig
658661
self._validate_package_type(lambda_function)
659662
return lambda_function
660663

samtranslator/plugins/globals/globals.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class Globals:
5757
"RecursiveLoop",
5858
"SourceKMSKeyArn",
5959
"TenancyConfig",
60+
"DurableConfig",
6061
],
6162
# Everything except
6263
# DefinitionBody: because its hard to reason about merge of Swagger dictionaries
@@ -107,6 +108,7 @@ class Globals:
107108
"RecursiveLoop",
108109
"SourceKMSKeyArn",
109110
"TenancyConfig",
111+
"DurableConfig",
110112
],
111113
}
112114

samtranslator/schema/schema.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142798,6 +142798,11 @@
142798142798
"title": "Description",
142799142799
"type": "string"
142800142800
},
142801+
"DurableConfig": {
142802+
"$ref": "#/definitions/AWS::Lambda::Function.DurableConfig",
142803+
"markdownDescription": "Configuration for durable function execution.",
142804+
"title": "DurableConfig"
142805+
},
142801142806
"Environment": {
142802142807
"$ref": "#/definitions/AWS::Lambda::Function.Environment",
142803142808
"markdownDescription": "Environment variables that are accessible from function code during execution.",
@@ -142977,6 +142982,22 @@
142977142982
},
142978142983
"type": "object"
142979142984
},
142985+
"AWS::Lambda::Function.DurableConfig": {
142986+
"additionalProperties": false,
142987+
"properties": {
142988+
"ExecutionTimeout": {
142989+
"markdownDescription": "The maximum execution timeout in seconds for durable function executions.",
142990+
"title": "ExecutionTimeout",
142991+
"type": "number"
142992+
},
142993+
"RetentionPeriodInDays": {
142994+
"markdownDescription": "The retention period in days for durable function execution history.",
142995+
"title": "RetentionPeriodInDays",
142996+
"type": "number"
142997+
}
142998+
},
142999+
"type": "object"
143000+
},
142980143001
"AWS::Lambda::Function.Environment": {
142981143002
"additionalProperties": false,
142982143003
"properties": {
@@ -278453,6 +278474,9 @@
278453278474
"markdownDescription": "A description of the function\\. \n*Type*: String \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`Description`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-description) property of an `AWS::Lambda::Function` resource\\.",
278454278475
"title": "Description"
278455278476
},
278477+
"DurableConfig": {
278478+
"$ref": "#/definitions/PassThroughProp"
278479+
},
278456278480
"Environment": {
278457278481
"$ref": "#/definitions/AWS::Lambda::Function.Environment",
278458278482
"markdownDescription": "The configuration for the runtime environment\\. \n*Type*: [Environment](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-environment.html) \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`Environment`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-environment.html) property of an `AWS::Lambda::Function` resource\\.",
@@ -278704,6 +278728,9 @@
278704278728
"title": "Description",
278705278729
"type": "string"
278706278730
},
278731+
"DurableConfig": {
278732+
"$ref": "#/definitions/PassThroughProp"
278733+
},
278707278734
"Environment": {
278708278735
"$ref": "#/definitions/AWS::Lambda::Function.Environment",
278709278736
"markdownDescription": "The configuration for the runtime environment\\. \n*Type*: [Environment](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-environment.html) \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`Environment`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-environment.html) property of an `AWS::Lambda::Function` resource\\.",

schema_source/cloudformation.schema.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142749,6 +142749,11 @@
142749142749
"title": "Description",
142750142750
"type": "string"
142751142751
},
142752+
"DurableConfig": {
142753+
"$ref": "#/definitions/AWS::Lambda::Function.DurableConfig",
142754+
"markdownDescription": "Configuration for durable function execution.",
142755+
"title": "DurableConfig"
142756+
},
142752142757
"Environment": {
142753142758
"$ref": "#/definitions/AWS::Lambda::Function.Environment",
142754142759
"markdownDescription": "Environment variables that are accessible from function code during execution.",
@@ -143119,6 +143124,22 @@
143119143124
},
143120143125
"type": "object"
143121143126
},
143127+
"AWS::Lambda::Function.DurableConfig": {
143128+
"additionalProperties": false,
143129+
"properties": {
143130+
"ExecutionTimeout": {
143131+
"markdownDescription": "The maximum execution timeout in seconds for durable function executions.",
143132+
"title": "ExecutionTimeout",
143133+
"type": "number"
143134+
},
143135+
"RetentionPeriodInDays": {
143136+
"markdownDescription": "The retention period in days for durable function execution history.",
143137+
"title": "RetentionPeriodInDays",
143138+
"type": "number"
143139+
}
143140+
},
143141+
"type": "object"
143142+
},
143122143143
"AWS::Lambda::LayerVersion": {
143123143144
"additionalProperties": false,
143124143145
"properties": {

schema_source/sam.schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5476,6 +5476,9 @@
54765476
"markdownDescription": "A description of the function\\. \n*Type*: String \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`Description`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-description) property of an `AWS::Lambda::Function` resource\\.",
54775477
"title": "Description"
54785478
},
5479+
"DurableConfig": {
5480+
"$ref": "#/definitions/PassThroughProp"
5481+
},
54795482
"Environment": {
54805483
"__samPassThrough": {
54815484
"markdownDescriptionOverride": "The configuration for the runtime environment\\. \n*Type*: [Environment](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-environment.html) \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`Environment`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-environment.html) property of an `AWS::Lambda::Function` resource\\.",
@@ -5853,6 +5856,9 @@
58535856
],
58545857
"title": "Description"
58555858
},
5859+
"DurableConfig": {
5860+
"$ref": "#/definitions/PassThroughProp"
5861+
},
58565862
"Environment": {
58575863
"__samPassThrough": {
58585864
"markdownDescriptionOverride": "The configuration for the runtime environment\\. \n*Type*: [Environment](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-environment.html) \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`Environment`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-environment.html) property of an `AWS::Lambda::Function` resource\\.",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Resources:
2+
FunctionWithDurableConfig:
3+
Type: AWS::Serverless::Function
4+
Properties:
5+
CodeUri: s3://sam-demo-bucket/hello.zip
6+
Handler: hello.handler
7+
Runtime: python3.9
8+
DurableConfig:
9+
ExecutionTimeout: 3600
10+
RetentionPeriodInDays: 45
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Globals:
2+
Function:
3+
Runtime: python3.11
4+
Handler: index.handler
5+
DurableConfig:
6+
ExecutionTimeout: 3600
7+
RetentionPeriodInDays: 30
8+
9+
Resources:
10+
DurableFunctionWithGlobals:
11+
Type: AWS::Serverless::Function
12+
Properties:
13+
CodeUri: s3://my-bucket/my-function.zip
14+
15+
DurableFunctionWithOverride:
16+
Type: AWS::Serverless::Function
17+
Properties:
18+
CodeUri: s3://my-bucket/my-function.zip
19+
DurableConfig:
20+
ExecutionTimeout: 7200
21+
RetentionPeriodInDays: 7
22+
23+
RegularFunction:
24+
Type: AWS::Serverless::Function
25+
Properties:
26+
CodeUri: s3://my-bucket/my-function.zip
27+
# This function should inherit the global DurableConfig

0 commit comments

Comments
 (0)