Skip to content

Commit

Permalink
Remove property validations for lambda resources (#2928)
Browse files Browse the repository at this point in the history
  • Loading branch information
xazhao authored Feb 22, 2023
1 parent ab91e9a commit 06e6e28
Show file tree
Hide file tree
Showing 5 changed files with 259 additions and 78 deletions.
155 changes: 77 additions & 78 deletions samtranslator/model/lambda_.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
from typing import Any, Dict, List, Optional, Union

from samtranslator.model import PassThroughProperty, PropertyType, Resource
from samtranslator.model import GeneratedProperty, Resource
from samtranslator.model.intrinsics import fnGetAtt, ref
from samtranslator.model.types import IS_DICT, IS_STR, any_type, is_type, list_of, one_of
from samtranslator.utils.types import Intrinsicable


class LambdaFunction(Resource):
resource_type = "AWS::Lambda::Function"
property_types = {
"Code": PropertyType(True, IS_DICT),
"PackageType": PropertyType(False, IS_STR),
"DeadLetterConfig": PropertyType(False, IS_DICT),
"Description": PropertyType(False, IS_STR),
"FunctionName": PropertyType(False, IS_STR),
"Handler": PropertyType(False, IS_STR),
"MemorySize": PropertyType(False, is_type(int)),
"Role": PropertyType(False, IS_STR),
"Runtime": PropertyType(False, IS_STR),
"Timeout": PropertyType(False, is_type(int)),
"VpcConfig": PropertyType(False, IS_DICT),
"Environment": PropertyType(False, IS_DICT),
"Tags": PropertyType(False, list_of(IS_DICT)),
"TracingConfig": PropertyType(False, IS_DICT),
"KmsKeyArn": PropertyType(False, one_of(IS_DICT, IS_STR)),
"Layers": PropertyType(False, list_of(one_of(IS_STR, IS_DICT))),
"ReservedConcurrentExecutions": PropertyType(False, any_type()),
"FileSystemConfigs": PropertyType(False, list_of(IS_DICT)),
"CodeSigningConfigArn": PropertyType(False, IS_STR),
"ImageConfig": PropertyType(False, IS_DICT),
"Architectures": PropertyType(False, list_of(one_of(IS_STR, IS_DICT))),
"SnapStart": PropertyType(False, IS_DICT),
"EphemeralStorage": PropertyType(False, IS_DICT),
"RuntimeManagementConfig": PropertyType(False, IS_DICT),
"Code": GeneratedProperty(),
"PackageType": GeneratedProperty(),
"DeadLetterConfig": GeneratedProperty(),
"Description": GeneratedProperty(),
"FunctionName": GeneratedProperty(),
"Handler": GeneratedProperty(),
"MemorySize": GeneratedProperty(),
"Role": GeneratedProperty(),
"Runtime": GeneratedProperty(),
"Timeout": GeneratedProperty(),
"VpcConfig": GeneratedProperty(),
"Environment": GeneratedProperty(),
"Tags": GeneratedProperty(),
"TracingConfig": GeneratedProperty(),
"KmsKeyArn": GeneratedProperty(),
"Layers": GeneratedProperty(),
"ReservedConcurrentExecutions": GeneratedProperty(),
"FileSystemConfigs": GeneratedProperty(),
"CodeSigningConfigArn": GeneratedProperty(),
"ImageConfig": GeneratedProperty(),
"Architectures": GeneratedProperty(),
"SnapStart": GeneratedProperty(),
"EphemeralStorage": GeneratedProperty(),
"RuntimeManagementConfig": GeneratedProperty(),
}

Code: Dict[str, Any]
Expand Down Expand Up @@ -66,10 +65,10 @@ class LambdaFunction(Resource):
class LambdaVersion(Resource):
resource_type = "AWS::Lambda::Version"
property_types = {
"CodeSha256": PropertyType(False, IS_STR),
"Description": PropertyType(False, IS_STR),
"FunctionName": PropertyType(True, one_of(IS_STR, IS_DICT)),
"RuntimeManagementConfig": PropertyType(False, IS_DICT),
"CodeSha256": GeneratedProperty(),
"Description": GeneratedProperty(),
"FunctionName": GeneratedProperty(),
"RuntimeManagementConfig": GeneratedProperty(),
}

runtime_attrs = {
Expand All @@ -81,11 +80,11 @@ class LambdaVersion(Resource):
class LambdaAlias(Resource):
resource_type = "AWS::Lambda::Alias"
property_types = {
"Description": PropertyType(False, IS_STR),
"Name": PropertyType(False, IS_STR),
"FunctionName": PropertyType(True, one_of(IS_STR, IS_DICT)),
"FunctionVersion": PropertyType(True, one_of(IS_STR, IS_DICT)),
"ProvisionedConcurrencyConfig": PropertyType(False, IS_DICT),
"Description": GeneratedProperty(),
"Name": GeneratedProperty(),
"FunctionName": GeneratedProperty(),
"FunctionVersion": GeneratedProperty(),
"ProvisionedConcurrencyConfig": GeneratedProperty(),
}

runtime_attrs = {"arn": lambda self: ref(self.logical_id)}
Expand All @@ -94,28 +93,28 @@ class LambdaAlias(Resource):
class LambdaEventSourceMapping(Resource):
resource_type = "AWS::Lambda::EventSourceMapping"
property_types = {
"BatchSize": PropertyType(False, is_type(int)),
"Enabled": PropertyType(False, is_type(bool)),
"EventSourceArn": PropertyType(False, IS_STR),
"FunctionName": PropertyType(True, IS_STR),
"MaximumBatchingWindowInSeconds": PropertyType(False, is_type(int)),
"MaximumRetryAttempts": PropertyType(False, is_type(int)),
"BisectBatchOnFunctionError": PropertyType(False, is_type(bool)),
"MaximumRecordAgeInSeconds": PropertyType(False, is_type(int)),
"DestinationConfig": PropertyType(False, IS_DICT),
"ParallelizationFactor": PropertyType(False, is_type(int)),
"StartingPosition": PropertyType(False, IS_STR),
"StartingPositionTimestamp": PassThroughProperty(False),
"Topics": PropertyType(False, is_type(list)),
"Queues": PropertyType(False, is_type(list)),
"SourceAccessConfigurations": PropertyType(False, is_type(list)),
"TumblingWindowInSeconds": PropertyType(False, is_type(int)),
"FunctionResponseTypes": PropertyType(False, is_type(list)),
"SelfManagedEventSource": PropertyType(False, IS_DICT),
"FilterCriteria": PropertyType(False, IS_DICT),
"AmazonManagedKafkaEventSourceConfig": PropertyType(False, IS_DICT),
"SelfManagedKafkaEventSourceConfig": PropertyType(False, IS_DICT),
"ScalingConfig": PropertyType(False, IS_DICT),
"BatchSize": GeneratedProperty(),
"Enabled": GeneratedProperty(),
"EventSourceArn": GeneratedProperty(),
"FunctionName": GeneratedProperty(),
"MaximumBatchingWindowInSeconds": GeneratedProperty(),
"MaximumRetryAttempts": GeneratedProperty(),
"BisectBatchOnFunctionError": GeneratedProperty(),
"MaximumRecordAgeInSeconds": GeneratedProperty(),
"DestinationConfig": GeneratedProperty(),
"ParallelizationFactor": GeneratedProperty(),
"StartingPosition": GeneratedProperty(),
"StartingPositionTimestamp": GeneratedProperty(),
"Topics": GeneratedProperty(),
"Queues": GeneratedProperty(),
"SourceAccessConfigurations": GeneratedProperty(),
"TumblingWindowInSeconds": GeneratedProperty(),
"FunctionResponseTypes": GeneratedProperty(),
"SelfManagedEventSource": GeneratedProperty(),
"FilterCriteria": GeneratedProperty(),
"AmazonManagedKafkaEventSourceConfig": GeneratedProperty(),
"SelfManagedKafkaEventSourceConfig": GeneratedProperty(),
"ScalingConfig": GeneratedProperty(),
}

runtime_attrs = {"name": lambda self: ref(self.logical_id)}
Expand All @@ -124,24 +123,24 @@ class LambdaEventSourceMapping(Resource):
class LambdaPermission(Resource):
resource_type = "AWS::Lambda::Permission"
property_types = {
"Action": PropertyType(True, IS_STR),
"FunctionName": PropertyType(True, IS_STR),
"Principal": PropertyType(True, IS_STR),
"SourceAccount": PropertyType(False, IS_STR),
"SourceArn": PropertyType(False, IS_STR),
"EventSourceToken": PropertyType(False, IS_STR),
"FunctionUrlAuthType": PropertyType(False, IS_STR),
"Action": GeneratedProperty(),
"FunctionName": GeneratedProperty(),
"Principal": GeneratedProperty(),
"SourceAccount": GeneratedProperty(),
"SourceArn": GeneratedProperty(),
"EventSourceToken": GeneratedProperty(),
"FunctionUrlAuthType": GeneratedProperty(),
}


class LambdaEventInvokeConfig(Resource):
resource_type = "AWS::Lambda::EventInvokeConfig"
property_types = {
"DestinationConfig": PropertyType(False, IS_DICT),
"FunctionName": PropertyType(True, IS_STR),
"MaximumEventAgeInSeconds": PropertyType(False, is_type(int)),
"MaximumRetryAttempts": PropertyType(False, is_type(int)),
"Qualifier": PropertyType(True, IS_STR),
"DestinationConfig": GeneratedProperty(),
"FunctionName": GeneratedProperty(),
"MaximumEventAgeInSeconds": GeneratedProperty(),
"MaximumRetryAttempts": GeneratedProperty(),
"Qualifier": GeneratedProperty(),
}


Expand All @@ -150,12 +149,12 @@ class LambdaLayerVersion(Resource):

resource_type = "AWS::Lambda::LayerVersion"
property_types = {
"Content": PropertyType(True, IS_DICT),
"Description": PropertyType(False, IS_STR),
"LayerName": PropertyType(False, IS_STR),
"CompatibleArchitectures": PropertyType(False, list_of(one_of(IS_STR, IS_DICT))),
"CompatibleRuntimes": PropertyType(False, list_of(one_of(IS_STR, IS_DICT))),
"LicenseInfo": PropertyType(False, IS_STR),
"Content": GeneratedProperty(),
"Description": GeneratedProperty(),
"LayerName": GeneratedProperty(),
"CompatibleArchitectures": GeneratedProperty(),
"CompatibleRuntimes": GeneratedProperty(),
"LicenseInfo": GeneratedProperty(),
}

Content: Dict[str, Any]
Expand All @@ -171,7 +170,7 @@ class LambdaLayerVersion(Resource):
class LambdaUrl(Resource):
resource_type = "AWS::Lambda::Url"
property_types = {
"TargetFunctionArn": PropertyType(True, one_of(IS_STR, IS_DICT)),
"AuthType": PropertyType(True, IS_STR),
"Cors": PropertyType(False, IS_DICT),
"TargetFunctionArn": GeneratedProperty(),
"AuthType": GeneratedProperty(),
"Cors": GeneratedProperty(),
}
8 changes: 8 additions & 0 deletions tests/translator/input/function_string_memorysize.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Resources:
MinimalFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: hello.handler
Runtime: python3.7
MemorySize: '700'
58 changes: 58 additions & 0 deletions tests/translator/output/aws-cn/function_string_memorysize.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"Resources": {
"MinimalFunction": {
"Properties": {
"Code": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "hello.zip"
},
"Handler": "hello.handler",
"MemorySize": "700",
"Role": {
"Fn::GetAtt": [
"MinimalFunctionRole",
"Arn"
]
},
"Runtime": "python3.7",
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::Lambda::Function"
},
"MinimalFunctionRole": {
"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"
}
}
}
58 changes: 58 additions & 0 deletions tests/translator/output/aws-us-gov/function_string_memorysize.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"Resources": {
"MinimalFunction": {
"Properties": {
"Code": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "hello.zip"
},
"Handler": "hello.handler",
"MemorySize": "700",
"Role": {
"Fn::GetAtt": [
"MinimalFunctionRole",
"Arn"
]
},
"Runtime": "python3.7",
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::Lambda::Function"
},
"MinimalFunctionRole": {
"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"
}
}
}
58 changes: 58 additions & 0 deletions tests/translator/output/function_string_memorysize.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"Resources": {
"MinimalFunction": {
"Properties": {
"Code": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "hello.zip"
},
"Handler": "hello.handler",
"MemorySize": "700",
"Role": {
"Fn::GetAtt": [
"MinimalFunctionRole",
"Arn"
]
},
"Runtime": "python3.7",
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
},
"Type": "AWS::Lambda::Function"
},
"MinimalFunctionRole": {
"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"
}
}
}

0 comments on commit 06e6e28

Please sign in to comment.