diff --git a/.cfnlintrc.yaml b/.cfnlintrc.yaml index 5fd8d0032..ea8e0e16a 100644 --- a/.cfnlintrc.yaml +++ b/.cfnlintrc.yaml @@ -149,6 +149,7 @@ ignore_templates: - tests/translator/output/**/function_with_tenancy_and_api_event.json # cfnlint is not updated to recognize the TenancyConfig property - tests/translator/output/**/function_with_tenancy_and_httpapi_event.json # cfnlint is not updated to recognize the TenancyConfig property - tests/translator/output/**/function_with_tenancy_config_global.json # cfnlint is not updated to recognize the TenancyConfig property + - tests/translator/output/**/*durable_config*.json # TODO: Remove this once Durable Function is launched in CFN ignore_checks: - E2531 # Deprecated runtime; not relevant for transform tests diff --git a/samtranslator/__init__.py b/samtranslator/__init__.py index 3ad358e22..c64333da5 100644 --- a/samtranslator/__init__.py +++ b/samtranslator/__init__.py @@ -1 +1 @@ -__version__ = "1.104.0" +__version__ = "1.105.0" diff --git a/samtranslator/internal/schema_source/aws_serverless_function.py b/samtranslator/internal/schema_source/aws_serverless_function.py index 13d716cfe..1ff13cb87 100644 --- a/samtranslator/internal/schema_source/aws_serverless_function.py +++ b/samtranslator/internal/schema_source/aws_serverless_function.py @@ -679,6 +679,7 @@ class Properties(BaseModel): ) # TODO: add documentation PublishToLatestPublished: Optional[SamIntrinsicable[Union[str, bool]]] # TODO: add documentation TenancyConfig: Optional[PassThroughProp] # TODO: add documentation + DurableConfig: Optional[PassThroughProp] # TODO: add documentation class Globals(BaseModel): @@ -746,6 +747,7 @@ class Globals(BaseModel): ) # TODO: add documentation PublishToLatestPublished: Optional[SamIntrinsicable[Union[str, bool]]] # TODO: add documentation TenancyConfig: Optional[PassThroughProp] # TODO: add documentation + DurableConfig: Optional[PassThroughProp] # TODO: add documentation class Resource(ResourceAttributes): diff --git a/samtranslator/model/lambda_.py b/samtranslator/model/lambda_.py index 652d66e0f..243a069d5 100644 --- a/samtranslator/model/lambda_.py +++ b/samtranslator/model/lambda_.py @@ -40,6 +40,7 @@ class LambdaFunction(Resource): "FunctionScalingConfig": GeneratedProperty(), "PublishToLatestPublished": GeneratedProperty(), "TenancyConfig": GeneratedProperty(), + "DurableConfig": GeneratedProperty(), } Code: Dict[str, Any] @@ -72,6 +73,7 @@ class LambdaFunction(Resource): FunctionScalingConfig: Optional[Dict[str, Any]] PublishToLatestPublished: Optional[Dict[str, Any]] TenancyConfig: Optional[Dict[str, Any]] + DurableConfig: Optional[Dict[str, Any]] runtime_attrs = {"name": lambda self: ref(self.logical_id), "arn": lambda self: fnGetAtt(self.logical_id, "Arn")} diff --git a/samtranslator/model/sam_resources.py b/samtranslator/model/sam_resources.py index fde581d90..7d462b959 100644 --- a/samtranslator/model/sam_resources.py +++ b/samtranslator/model/sam_resources.py @@ -198,6 +198,7 @@ class SamFunction(SamResourceMacro): "VersionDeletionPolicy": PropertyType(False, IS_STR_ENUM(["Delete", "Retain"])), "PublishToLatestPublished": PassThroughProperty(False), "TenancyConfig": PassThroughProperty(False), + "DurableConfig": PropertyType(False, IS_DICT), } FunctionName: Optional[Intrinsicable[str]] @@ -247,6 +248,7 @@ class SamFunction(SamResourceMacro): PublishToLatestPublished: Optional[PassThrough] VersionDeletionPolicy: Optional[Intrinsicable[str]] TenancyConfig: Optional[Dict[str, Any]] + DurableConfig: Optional[Dict[str, Any]] event_resolver = ResourceTypeResolver( samtranslator.model.eventsources, @@ -690,6 +692,7 @@ def _construct_lambda_function(self, intrinsics_resolver: IntrinsicsResolver) -> lambda_function.LoggingConfig = self.LoggingConfig lambda_function.TenancyConfig = self.TenancyConfig lambda_function.RecursiveLoop = self.RecursiveLoop + lambda_function.DurableConfig = self.DurableConfig # Transform capacity provider configuration if self.CapacityProviderConfig: diff --git a/samtranslator/plugins/globals/globals.py b/samtranslator/plugins/globals/globals.py index 7e5542014..1373b30db 100644 --- a/samtranslator/plugins/globals/globals.py +++ b/samtranslator/plugins/globals/globals.py @@ -57,6 +57,7 @@ class Globals: "RecursiveLoop", "SourceKMSKeyArn", "TenancyConfig", + "DurableConfig", "CapacityProviderConfig", "FunctionScalingConfig", "PublishToLatestPublished", @@ -117,6 +118,7 @@ class Globals: unreleased_properties: Dict[str, List[str]] = { SamResourceType.Function.value: [ "TenancyConfig", + "DurableConfig", "CapacityProviderConfig", "FunctionScalingConfig", "PublishToLatestPublished", diff --git a/samtranslator/schema/schema.json b/samtranslator/schema/schema.json index ed772bef1..ae44d3590 100644 --- a/samtranslator/schema/schema.json +++ b/samtranslator/schema/schema.json @@ -142798,6 +142798,11 @@ "title": "Description", "type": "string" }, + "DurableConfig": { + "$ref": "#/definitions/AWS::Lambda::Function.DurableConfig", + "markdownDescription": "Configuration for durable function execution.", + "title": "DurableConfig" + }, "Environment": { "$ref": "#/definitions/AWS::Lambda::Function.Environment", "markdownDescription": "Environment variables that are accessible from function code during execution.", @@ -142977,6 +142982,22 @@ }, "type": "object" }, + "AWS::Lambda::Function.DurableConfig": { + "additionalProperties": false, + "properties": { + "ExecutionTimeout": { + "markdownDescription": "The maximum execution timeout in seconds for durable function executions.", + "title": "ExecutionTimeout", + "type": "number" + }, + "RetentionPeriodInDays": { + "markdownDescription": "The retention period in days for durable function execution history.", + "title": "RetentionPeriodInDays", + "type": "number" + } + }, + "type": "object" + }, "AWS::Lambda::Function.Environment": { "additionalProperties": false, "properties": { @@ -278805,6 +278826,9 @@ "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\\.", "title": "Description" }, + "DurableConfig": { + "$ref": "#/definitions/PassThroughProp" + }, "Environment": { "$ref": "#/definitions/AWS::Lambda::Function.Environment", "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\\.", @@ -279097,6 +279121,9 @@ "title": "Description", "type": "string" }, + "DurableConfig": { + "$ref": "#/definitions/PassThroughProp" + }, "Environment": { "$ref": "#/definitions/AWS::Lambda::Function.Environment", "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\\.", diff --git a/schema_source/cloudformation.schema.json b/schema_source/cloudformation.schema.json index b85da2265..9c8354f47 100644 --- a/schema_source/cloudformation.schema.json +++ b/schema_source/cloudformation.schema.json @@ -142749,6 +142749,11 @@ "title": "Description", "type": "string" }, + "DurableConfig": { + "$ref": "#/definitions/AWS::Lambda::Function.DurableConfig", + "markdownDescription": "Configuration for durable function execution.", + "title": "DurableConfig" + }, "Environment": { "$ref": "#/definitions/AWS::Lambda::Function.Environment", "markdownDescription": "Environment variables that are accessible from function code during execution.", @@ -143119,6 +143124,22 @@ }, "type": "object" }, + "AWS::Lambda::Function.DurableConfig": { + "additionalProperties": false, + "properties": { + "ExecutionTimeout": { + "markdownDescription": "The maximum execution timeout in seconds for durable function executions.", + "title": "ExecutionTimeout", + "type": "number" + }, + "RetentionPeriodInDays": { + "markdownDescription": "The retention period in days for durable function execution history.", + "title": "RetentionPeriodInDays", + "type": "number" + } + }, + "type": "object" + }, "AWS::Lambda::LayerVersion": { "additionalProperties": false, "properties": { diff --git a/schema_source/sam.schema.json b/schema_source/sam.schema.json index cd4da3d88..71e3d80b0 100644 --- a/schema_source/sam.schema.json +++ b/schema_source/sam.schema.json @@ -5828,6 +5828,9 @@ "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\\.", "title": "Description" }, + "DurableConfig": { + "$ref": "#/definitions/PassThroughProp" + }, "Environment": { "__samPassThrough": { "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\\.", @@ -6246,6 +6249,9 @@ ], "title": "Description" }, + "DurableConfig": { + "$ref": "#/definitions/PassThroughProp" + }, "Environment": { "__samPassThrough": { "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\\.", diff --git a/tests/translator/input/function_with_durable_config.yaml b/tests/translator/input/function_with_durable_config.yaml new file mode 100644 index 000000000..ee2b774a2 --- /dev/null +++ b/tests/translator/input/function_with_durable_config.yaml @@ -0,0 +1,10 @@ +Resources: + FunctionWithDurableConfig: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python3.9 + DurableConfig: + ExecutionTimeout: 3600 + RetentionPeriodInDays: 45 diff --git a/tests/translator/input/function_with_durable_config_globals.yaml b/tests/translator/input/function_with_durable_config_globals.yaml new file mode 100644 index 000000000..6af020c65 --- /dev/null +++ b/tests/translator/input/function_with_durable_config_globals.yaml @@ -0,0 +1,27 @@ +Globals: + Function: + Runtime: python3.11 + Handler: index.handler + DurableConfig: + ExecutionTimeout: 3600 + RetentionPeriodInDays: 30 + +Resources: + DurableFunctionWithGlobals: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://my-bucket/my-function.zip + + DurableFunctionWithOverride: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://my-bucket/my-function.zip + DurableConfig: + ExecutionTimeout: 7200 + RetentionPeriodInDays: 7 + + RegularFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://my-bucket/my-function.zip + # This function should inherit the global DurableConfig diff --git a/tests/translator/input/globals_for_function.yaml b/tests/translator/input/globals_for_function.yaml index a4cf09729..96e24eeb8 100644 --- a/tests/translator/input/globals_for_function.yaml +++ b/tests/translator/input/globals_for_function.yaml @@ -34,6 +34,9 @@ Globals: LogGroup: myJsonStructuredLogs RecursiveLoop: ALLOW SourceKMSKeyArn: arn:aws:kms:us-west-2:123456789012:key/dec86919-7219-4e8d-8871-7f1609df2c7f + DurableConfig: + ExecutionTimeout: 3600 + RetentionPeriodInDays: 30 @@ -69,3 +72,6 @@ Resources: UpdateRuntimeOn: FunctionChange RecursiveLoop: TERMINATE SourceKMSKeyArn: arn:aws:kms:us-west-2:987654321098:key/dec86919-7219-4e8d-8871-7f1609df2c7f + DurableConfig: + ExecutionTimeout: 7200 + RetentionPeriodInDays: 7 diff --git a/tests/translator/output/aws-cn/function_with_durable_config.json b/tests/translator/output/aws-cn/function_with_durable_config.json new file mode 100644 index 000000000..f4ef270d1 --- /dev/null +++ b/tests/translator/output/aws-cn/function_with_durable_config.json @@ -0,0 +1,61 @@ +{ + "Resources": { + "FunctionWithDurableConfig": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "DurableConfig": { + "ExecutionTimeout": 3600, + "RetentionPeriodInDays": 45 + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FunctionWithDurableConfigRole", + "Arn" + ] + }, + "Runtime": "python3.9", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithDurableConfigRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + } + } +} diff --git a/tests/translator/output/aws-cn/function_with_durable_config_globals.json b/tests/translator/output/aws-cn/function_with_durable_config_globals.json new file mode 100644 index 000000000..11faea418 --- /dev/null +++ b/tests/translator/output/aws-cn/function_with_durable_config_globals.json @@ -0,0 +1,175 @@ +{ + "Resources": { + "DurableFunctionWithGlobals": { + "Properties": { + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "my-function.zip" + }, + "DurableConfig": { + "ExecutionTimeout": 3600, + "RetentionPeriodInDays": 30 + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "DurableFunctionWithGlobalsRole", + "Arn" + ] + }, + "Runtime": "python3.11", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "DurableFunctionWithGlobalsRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "DurableFunctionWithOverride": { + "Properties": { + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "my-function.zip" + }, + "DurableConfig": { + "ExecutionTimeout": 7200, + "RetentionPeriodInDays": 7 + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "DurableFunctionWithOverrideRole", + "Arn" + ] + }, + "Runtime": "python3.11", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "DurableFunctionWithOverrideRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "RegularFunction": { + "Properties": { + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "my-function.zip" + }, + "DurableConfig": { + "ExecutionTimeout": 3600, + "RetentionPeriodInDays": 30 + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "RegularFunctionRole", + "Arn" + ] + }, + "Runtime": "python3.11", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "RegularFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + } + } +} diff --git a/tests/translator/output/aws-cn/globals_for_function.json b/tests/translator/output/aws-cn/globals_for_function.json index 293cf5109..bce45277b 100644 --- a/tests/translator/output/aws-cn/globals_for_function.json +++ b/tests/translator/output/aws-cn/globals_for_function.json @@ -10,6 +10,10 @@ "S3Key": "hello.zip", "SourceKMSKeyArn": "arn:aws:kms:us-west-2:987654321098:key/dec86919-7219-4e8d-8871-7f1609df2c7f" }, + "DurableConfig": { + "ExecutionTimeout": 7200, + "RetentionPeriodInDays": 7 + }, "Environment": { "Variables": { "Var1": "value1", @@ -153,6 +157,10 @@ "S3Key": "global.zip", "SourceKMSKeyArn": "arn:aws:kms:us-west-2:123456789012:key/dec86919-7219-4e8d-8871-7f1609df2c7f" }, + "DurableConfig": { + "ExecutionTimeout": 3600, + "RetentionPeriodInDays": 30 + }, "Environment": { "Variables": { "Var1": "value1", diff --git a/tests/translator/output/aws-us-gov/function_with_durable_config.json b/tests/translator/output/aws-us-gov/function_with_durable_config.json new file mode 100644 index 000000000..841337ed9 --- /dev/null +++ b/tests/translator/output/aws-us-gov/function_with_durable_config.json @@ -0,0 +1,61 @@ +{ + "Resources": { + "FunctionWithDurableConfig": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "DurableConfig": { + "ExecutionTimeout": 3600, + "RetentionPeriodInDays": 45 + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FunctionWithDurableConfigRole", + "Arn" + ] + }, + "Runtime": "python3.9", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithDurableConfigRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + } + } +} diff --git a/tests/translator/output/aws-us-gov/function_with_durable_config_globals.json b/tests/translator/output/aws-us-gov/function_with_durable_config_globals.json new file mode 100644 index 000000000..acd1d77ad --- /dev/null +++ b/tests/translator/output/aws-us-gov/function_with_durable_config_globals.json @@ -0,0 +1,175 @@ +{ + "Resources": { + "DurableFunctionWithGlobals": { + "Properties": { + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "my-function.zip" + }, + "DurableConfig": { + "ExecutionTimeout": 3600, + "RetentionPeriodInDays": 30 + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "DurableFunctionWithGlobalsRole", + "Arn" + ] + }, + "Runtime": "python3.11", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "DurableFunctionWithGlobalsRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "DurableFunctionWithOverride": { + "Properties": { + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "my-function.zip" + }, + "DurableConfig": { + "ExecutionTimeout": 7200, + "RetentionPeriodInDays": 7 + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "DurableFunctionWithOverrideRole", + "Arn" + ] + }, + "Runtime": "python3.11", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "DurableFunctionWithOverrideRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "RegularFunction": { + "Properties": { + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "my-function.zip" + }, + "DurableConfig": { + "ExecutionTimeout": 3600, + "RetentionPeriodInDays": 30 + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "RegularFunctionRole", + "Arn" + ] + }, + "Runtime": "python3.11", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "RegularFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + } + } +} diff --git a/tests/translator/output/aws-us-gov/globals_for_function.json b/tests/translator/output/aws-us-gov/globals_for_function.json index fceebdcdd..8b8ad102b 100644 --- a/tests/translator/output/aws-us-gov/globals_for_function.json +++ b/tests/translator/output/aws-us-gov/globals_for_function.json @@ -10,6 +10,10 @@ "S3Key": "hello.zip", "SourceKMSKeyArn": "arn:aws:kms:us-west-2:987654321098:key/dec86919-7219-4e8d-8871-7f1609df2c7f" }, + "DurableConfig": { + "ExecutionTimeout": 7200, + "RetentionPeriodInDays": 7 + }, "Environment": { "Variables": { "Var1": "value1", @@ -153,6 +157,10 @@ "S3Key": "global.zip", "SourceKMSKeyArn": "arn:aws:kms:us-west-2:123456789012:key/dec86919-7219-4e8d-8871-7f1609df2c7f" }, + "DurableConfig": { + "ExecutionTimeout": 3600, + "RetentionPeriodInDays": 30 + }, "Environment": { "Variables": { "Var1": "value1", diff --git a/tests/translator/output/function_with_durable_config.json b/tests/translator/output/function_with_durable_config.json new file mode 100644 index 000000000..04bd66bc6 --- /dev/null +++ b/tests/translator/output/function_with_durable_config.json @@ -0,0 +1,61 @@ +{ + "Resources": { + "FunctionWithDurableConfig": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "DurableConfig": { + "ExecutionTimeout": 3600, + "RetentionPeriodInDays": 45 + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FunctionWithDurableConfigRole", + "Arn" + ] + }, + "Runtime": "python3.9", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithDurableConfigRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + } + } +} diff --git a/tests/translator/output/function_with_durable_config_globals.json b/tests/translator/output/function_with_durable_config_globals.json new file mode 100644 index 000000000..075dfceaf --- /dev/null +++ b/tests/translator/output/function_with_durable_config_globals.json @@ -0,0 +1,175 @@ +{ + "Resources": { + "DurableFunctionWithGlobals": { + "Properties": { + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "my-function.zip" + }, + "DurableConfig": { + "ExecutionTimeout": 3600, + "RetentionPeriodInDays": 30 + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "DurableFunctionWithGlobalsRole", + "Arn" + ] + }, + "Runtime": "python3.11", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "DurableFunctionWithGlobalsRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "DurableFunctionWithOverride": { + "Properties": { + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "my-function.zip" + }, + "DurableConfig": { + "ExecutionTimeout": 7200, + "RetentionPeriodInDays": 7 + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "DurableFunctionWithOverrideRole", + "Arn" + ] + }, + "Runtime": "python3.11", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "DurableFunctionWithOverrideRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "RegularFunction": { + "Properties": { + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "my-function.zip" + }, + "DurableConfig": { + "ExecutionTimeout": 3600, + "RetentionPeriodInDays": 30 + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "RegularFunctionRole", + "Arn" + ] + }, + "Runtime": "python3.11", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "RegularFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + } + } +} diff --git a/tests/translator/output/globals_for_function.json b/tests/translator/output/globals_for_function.json index d3749cd9a..27e1a1ebd 100644 --- a/tests/translator/output/globals_for_function.json +++ b/tests/translator/output/globals_for_function.json @@ -10,6 +10,10 @@ "S3Key": "hello.zip", "SourceKMSKeyArn": "arn:aws:kms:us-west-2:987654321098:key/dec86919-7219-4e8d-8871-7f1609df2c7f" }, + "DurableConfig": { + "ExecutionTimeout": 7200, + "RetentionPeriodInDays": 7 + }, "Environment": { "Variables": { "Var1": "value1", @@ -153,6 +157,10 @@ "S3Key": "global.zip", "SourceKMSKeyArn": "arn:aws:kms:us-west-2:123456789012:key/dec86919-7219-4e8d-8871-7f1609df2c7f" }, + "DurableConfig": { + "ExecutionTimeout": 3600, + "RetentionPeriodInDays": 30 + }, "Environment": { "Variables": { "Var1": "value1",