Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main to develop #3640

Merged
merged 5 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cfnlintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ ignore_templates:
- tests/translator/output/**/managed_policies_minimal.json # Intentionally has non-existent managed policy name
- tests/translator/output/**/function_with_mq.json # Property "EventSourceArn" can Fn::GetAtt to a resource of types [AWS::DynamoDB::GlobalTable, AWS::DynamoDB::Table, AWS::Kinesis::Stream, AWS::Kinesis::StreamConsumer, AWS::SQS::Queue]
- tests/translator/output/**/function_with_mq_using_autogen_role.json # Property "EventSourceArn" can Fn::GetAtt to a resource of types [AWS::DynamoDB::GlobalTable, AWS::DynamoDB::Table, AWS::Kinesis::Stream, AWS::Kinesis::StreamConsumer, AWS::SQS::Queue]
- tests/translator/output/**/function_with_recursive_loop.json # Invalid Property Resources/RecursiveLoopParameterFunction/Properties/RecursiveLoop
- tests/translator/output/**/function_with_tracing.json # Obsolete DependsOn on resource
- tests/translator/output/**/api_with_propagate_tags.json # TODO: Intentional error transform tests. Will be updated.
- tests/translator/output/**/function_with_intrinsics_resource_attribute.json # CFN now supports intrinsics in DeletionPolicy
Expand Down
2 changes: 1 addition & 1 deletion samtranslator/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.90.0"
__version__ = "1.91.0"
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ class ScheduleV2Event(BaseModel):
SnapStart = Optional[PassThroughProp] # TODO: check the type
RuntimeManagementConfig = Optional[PassThroughProp] # TODO: check the type
LoggingConfig = Optional[PassThroughProp] # TODO: add documentation
RecursiveLoop = Optional[PassThroughProp]


class Properties(BaseModel):
Expand Down Expand Up @@ -638,6 +639,7 @@ class Properties(BaseModel):
VersionDescription: Optional[PassThroughProp] = prop("VersionDescription")
VpcConfig: Optional[VpcConfig] = prop("VpcConfig")
LoggingConfig: Optional[PassThroughProp] # TODO: add documentation
RecursiveLoop: Optional[PassThroughProp] # TODO: add documentation


class Globals(BaseModel):
Expand Down Expand Up @@ -696,6 +698,7 @@ class Globals(BaseModel):
SnapStart: Optional[SnapStart] = prop("SnapStart")
RuntimeManagementConfig: Optional[RuntimeManagementConfig] = prop("RuntimeManagementConfig")
LoggingConfig: Optional[PassThroughProp] # TODO: add documentation
RecursiveLoop: Optional[PassThroughProp] # TODO: add documentation


class Resource(ResourceAttributes):
Expand Down
2 changes: 2 additions & 0 deletions samtranslator/model/lambda_.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class LambdaFunction(Resource):
"EphemeralStorage": GeneratedProperty(),
"RuntimeManagementConfig": GeneratedProperty(),
"LoggingConfig": GeneratedProperty(),
"RecursiveLoop": GeneratedProperty(),
}

Code: Dict[str, Any]
Expand Down Expand Up @@ -62,6 +63,7 @@ class LambdaFunction(Resource):
EphemeralStorage: Optional[Dict[str, Any]]
RuntimeManagementConfig: Optional[Dict[str, Any]]
LoggingConfig: Optional[Dict[str, Any]]
RecursiveLoop: Optional[str]

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

Expand Down
3 changes: 3 additions & 0 deletions samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class SamFunction(SamResourceMacro):
"FunctionUrlConfig": PropertyType(False, IS_DICT),
"RuntimeManagementConfig": PassThroughProperty(False),
"LoggingConfig": PassThroughProperty(False),
"RecursiveLoop": PassThroughProperty(False),
}

FunctionName: Optional[Intrinsicable[str]]
Expand Down Expand Up @@ -221,6 +222,7 @@ class SamFunction(SamResourceMacro):
SnapStart: Optional[Dict[str, Any]]
FunctionUrlConfig: Optional[Dict[str, Any]]
LoggingConfig: Optional[Dict[str, Any]]
RecursiveLoop: Optional[str]

event_resolver = ResourceTypeResolver(
samtranslator.model.eventsources,
Expand Down Expand Up @@ -605,6 +607,7 @@ def _construct_lambda_function(self, intrinsics_resolver: IntrinsicsResolver) ->

lambda_function.RuntimeManagementConfig = self.RuntimeManagementConfig # type: ignore[attr-defined]
lambda_function.LoggingConfig = self.LoggingConfig
lambda_function.RecursiveLoop = self.RecursiveLoop
self._validate_package_type(lambda_function)
return lambda_function

Expand Down
3 changes: 2 additions & 1 deletion samtranslator/plugins/globals/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Globals:
"FunctionUrlConfig",
"RuntimeManagementConfig",
"LoggingConfig",
"RecursiveLoop",
],
# Everything except
# DefinitionBody: because its hard to reason about merge of Swagger dictionaries
Expand Down Expand Up @@ -98,7 +99,7 @@ class Globals:
}
# unreleased_properties *must be* part of supported_properties too
unreleased_properties: Dict[str, List[str]] = {
SamResourceType.Function.value: ["RuntimeManagementConfig"],
SamResourceType.Function.value: ["RuntimeManagementConfig", "RecursiveLoop"],
}

def __init__(self, template: Dict[str, Any]) -> None:
Expand Down
6 changes: 6 additions & 0 deletions samtranslator/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -278758,6 +278758,9 @@
"markdownDescription": "The provisioned concurrency configuration of a function's alias\\. \n`ProvisionedConcurrencyConfig` can be specified only if the `AutoPublishAlias` is set\\. Otherwise, an error results\\.\n*Type*: [ProvisionedConcurrencyConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-alias.html#cfn-lambda-alias-provisionedconcurrencyconfig) \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`ProvisionedConcurrencyConfig`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-alias.html#cfn-lambda-alias-provisionedconcurrencyconfig) property of an `AWS::Lambda::Alias` resource\\.",
"title": "ProvisionedConcurrencyConfig"
},
"RecursiveLoop": {
"$ref": "#/definitions/PassThroughProp"
},
"ReservedConcurrentExecutions": {
"allOf": [
{
Expand Down Expand Up @@ -279137,6 +279140,9 @@
"markdownDescription": "The provisioned concurrency configuration of a function's alias\\. \n`ProvisionedConcurrencyConfig` can be specified only if the `AutoPublishAlias` is set\\. Otherwise, an error results\\.\n*Type*: [ProvisionedConcurrencyConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-alias.html#cfn-lambda-alias-provisionedconcurrencyconfig) \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`ProvisionedConcurrencyConfig`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-alias.html#cfn-lambda-alias-provisionedconcurrencyconfig) property of an `AWS::Lambda::Alias` resource\\.",
"title": "ProvisionedConcurrencyConfig"
},
"RecursiveLoop": {
"$ref": "#/definitions/PassThroughProp"
},
"ReservedConcurrentExecutions": {
"allOf": [
{
Expand Down
6 changes: 6 additions & 0 deletions schema_source/sam.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5457,6 +5457,9 @@
"markdownDescription": "The provisioned concurrency configuration of a function's alias\\. \n`ProvisionedConcurrencyConfig` can be specified only if the `AutoPublishAlias` is set\\. Otherwise, an error results\\.\n*Type*: [ProvisionedConcurrencyConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-alias.html#cfn-lambda-alias-provisionedconcurrencyconfig) \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`ProvisionedConcurrencyConfig`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-alias.html#cfn-lambda-alias-provisionedconcurrencyconfig) property of an `AWS::Lambda::Alias` resource\\.",
"title": "ProvisionedConcurrencyConfig"
},
"RecursiveLoop": {
"$ref": "#/definitions/PassThroughProp"
},
"ReservedConcurrentExecutions": {
"allOf": [
{
Expand Down Expand Up @@ -6027,6 +6030,9 @@
],
"title": "ProvisionedConcurrencyConfig"
},
"RecursiveLoop": {
"$ref": "#/definitions/PassThroughProp"
},
"ReservedConcurrentExecutions": {
"allOf": [
{
Expand Down
21 changes: 21 additions & 0 deletions tests/translator/input/function_with_recursive_loop.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Parameters:
RecursiveLoopParam:
Type: String
Default: ALLOW

Resources:
RecursiveLoopFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: hello.handler
Runtime: python3.9
RecursiveLoop: TERMINATE

RecursiveLoopParameterFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: hello.handler
Runtime: python3.9
RecursiveLoop: !Ref RecursiveLoopParam
2 changes: 2 additions & 0 deletions tests/translator/input/globals_for_function.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Globals:
UpdateRuntimeOn: Auto
LoggingConfig:
LogGroup: myJsonStructuredLogs
RecursiveLoop: ALLOW



Expand Down Expand Up @@ -65,3 +66,4 @@ Resources:
ReservedConcurrentExecutions: 100
RuntimeManagementConfig:
UpdateRuntimeOn: FunctionChange
RecursiveLoop: TERMINATE
120 changes: 120 additions & 0 deletions tests/translator/output/aws-cn/function_with_recursive_loop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{
"Parameters": {
"RecursiveLoopParam": {
"Default": "ALLOW",
"Type": "String"
}
},
"Resources": {
"RecursiveLoopFunction": {
"Properties": {
"Code": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "hello.zip"
},
"Handler": "hello.handler",
"RecursiveLoop": "TERMINATE",
"Role": {
"Fn::GetAtt": [
"RecursiveLoopFunctionRole",
"Arn"
]
},
"Runtime": "python3.9",
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::Lambda::Function"
},
"RecursiveLoopFunctionRole": {
"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"
},
"RecursiveLoopParameterFunction": {
"Properties": {
"Code": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "hello.zip"
},
"Handler": "hello.handler",
"RecursiveLoop": {
"Ref": "RecursiveLoopParam"
},
"Role": {
"Fn::GetAtt": [
"RecursiveLoopParameterFunctionRole",
"Arn"
]
},
"Runtime": "python3.9",
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::Lambda::Function"
},
"RecursiveLoopParameterFunctionRole": {
"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"
}
}
}
18 changes: 10 additions & 8 deletions tests/translator/output/aws-cn/globals_for_function.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"LogGroup": "myJsonStructuredLogs"
},
"MemorySize": 512,
"RecursiveLoop": "TERMINATE",
"ReservedConcurrentExecutions": 100,
"Role": {
"Fn::GetAtt": [
Expand All @@ -51,13 +52,13 @@
"Key": "lambda:createdBy",
"Value": "SAM"
},
{
"Key": "newtag1",
"Value": "newvalue1"
},
{
"Key": "tag1",
"Value": "value1"
},
{
"Key": "newtag1",
"Value": "newvalue1"
}
],
"Timeout": 100,
Expand Down Expand Up @@ -120,13 +121,13 @@
"Key": "lambda:createdBy",
"Value": "SAM"
},
{
"Key": "newtag1",
"Value": "newvalue1"
},
{
"Key": "tag1",
"Value": "value1"
},
{
"Key": "newtag1",
"Value": "newvalue1"
}
]
},
Expand Down Expand Up @@ -169,6 +170,7 @@
"LogGroup": "myJsonStructuredLogs"
},
"MemorySize": 1024,
"RecursiveLoop": "ALLOW",
"ReservedConcurrentExecutions": 50,
"Role": {
"Fn::GetAtt": [
Expand Down
Loading