Skip to content

Commit 06e6e28

Browse files
authored
Remove property validations for lambda resources (#2928)
1 parent ab91e9a commit 06e6e28

File tree

5 files changed

+259
-78
lines changed

5 files changed

+259
-78
lines changed

samtranslator/model/lambda_.py

Lines changed: 77 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,37 @@
11
from typing import Any, Dict, List, Optional, Union
22

3-
from samtranslator.model import PassThroughProperty, PropertyType, Resource
3+
from samtranslator.model import GeneratedProperty, Resource
44
from samtranslator.model.intrinsics import fnGetAtt, ref
5-
from samtranslator.model.types import IS_DICT, IS_STR, any_type, is_type, list_of, one_of
65
from samtranslator.utils.types import Intrinsicable
76

87

98
class LambdaFunction(Resource):
109
resource_type = "AWS::Lambda::Function"
1110
property_types = {
12-
"Code": PropertyType(True, IS_DICT),
13-
"PackageType": PropertyType(False, IS_STR),
14-
"DeadLetterConfig": PropertyType(False, IS_DICT),
15-
"Description": PropertyType(False, IS_STR),
16-
"FunctionName": PropertyType(False, IS_STR),
17-
"Handler": PropertyType(False, IS_STR),
18-
"MemorySize": PropertyType(False, is_type(int)),
19-
"Role": PropertyType(False, IS_STR),
20-
"Runtime": PropertyType(False, IS_STR),
21-
"Timeout": PropertyType(False, is_type(int)),
22-
"VpcConfig": PropertyType(False, IS_DICT),
23-
"Environment": PropertyType(False, IS_DICT),
24-
"Tags": PropertyType(False, list_of(IS_DICT)),
25-
"TracingConfig": PropertyType(False, IS_DICT),
26-
"KmsKeyArn": PropertyType(False, one_of(IS_DICT, IS_STR)),
27-
"Layers": PropertyType(False, list_of(one_of(IS_STR, IS_DICT))),
28-
"ReservedConcurrentExecutions": PropertyType(False, any_type()),
29-
"FileSystemConfigs": PropertyType(False, list_of(IS_DICT)),
30-
"CodeSigningConfigArn": PropertyType(False, IS_STR),
31-
"ImageConfig": PropertyType(False, IS_DICT),
32-
"Architectures": PropertyType(False, list_of(one_of(IS_STR, IS_DICT))),
33-
"SnapStart": PropertyType(False, IS_DICT),
34-
"EphemeralStorage": PropertyType(False, IS_DICT),
35-
"RuntimeManagementConfig": PropertyType(False, IS_DICT),
11+
"Code": GeneratedProperty(),
12+
"PackageType": GeneratedProperty(),
13+
"DeadLetterConfig": GeneratedProperty(),
14+
"Description": GeneratedProperty(),
15+
"FunctionName": GeneratedProperty(),
16+
"Handler": GeneratedProperty(),
17+
"MemorySize": GeneratedProperty(),
18+
"Role": GeneratedProperty(),
19+
"Runtime": GeneratedProperty(),
20+
"Timeout": GeneratedProperty(),
21+
"VpcConfig": GeneratedProperty(),
22+
"Environment": GeneratedProperty(),
23+
"Tags": GeneratedProperty(),
24+
"TracingConfig": GeneratedProperty(),
25+
"KmsKeyArn": GeneratedProperty(),
26+
"Layers": GeneratedProperty(),
27+
"ReservedConcurrentExecutions": GeneratedProperty(),
28+
"FileSystemConfigs": GeneratedProperty(),
29+
"CodeSigningConfigArn": GeneratedProperty(),
30+
"ImageConfig": GeneratedProperty(),
31+
"Architectures": GeneratedProperty(),
32+
"SnapStart": GeneratedProperty(),
33+
"EphemeralStorage": GeneratedProperty(),
34+
"RuntimeManagementConfig": GeneratedProperty(),
3635
}
3736

3837
Code: Dict[str, Any]
@@ -66,10 +65,10 @@ class LambdaFunction(Resource):
6665
class LambdaVersion(Resource):
6766
resource_type = "AWS::Lambda::Version"
6867
property_types = {
69-
"CodeSha256": PropertyType(False, IS_STR),
70-
"Description": PropertyType(False, IS_STR),
71-
"FunctionName": PropertyType(True, one_of(IS_STR, IS_DICT)),
72-
"RuntimeManagementConfig": PropertyType(False, IS_DICT),
68+
"CodeSha256": GeneratedProperty(),
69+
"Description": GeneratedProperty(),
70+
"FunctionName": GeneratedProperty(),
71+
"RuntimeManagementConfig": GeneratedProperty(),
7372
}
7473

7574
runtime_attrs = {
@@ -81,11 +80,11 @@ class LambdaVersion(Resource):
8180
class LambdaAlias(Resource):
8281
resource_type = "AWS::Lambda::Alias"
8382
property_types = {
84-
"Description": PropertyType(False, IS_STR),
85-
"Name": PropertyType(False, IS_STR),
86-
"FunctionName": PropertyType(True, one_of(IS_STR, IS_DICT)),
87-
"FunctionVersion": PropertyType(True, one_of(IS_STR, IS_DICT)),
88-
"ProvisionedConcurrencyConfig": PropertyType(False, IS_DICT),
83+
"Description": GeneratedProperty(),
84+
"Name": GeneratedProperty(),
85+
"FunctionName": GeneratedProperty(),
86+
"FunctionVersion": GeneratedProperty(),
87+
"ProvisionedConcurrencyConfig": GeneratedProperty(),
8988
}
9089

9190
runtime_attrs = {"arn": lambda self: ref(self.logical_id)}
@@ -94,28 +93,28 @@ class LambdaAlias(Resource):
9493
class LambdaEventSourceMapping(Resource):
9594
resource_type = "AWS::Lambda::EventSourceMapping"
9695
property_types = {
97-
"BatchSize": PropertyType(False, is_type(int)),
98-
"Enabled": PropertyType(False, is_type(bool)),
99-
"EventSourceArn": PropertyType(False, IS_STR),
100-
"FunctionName": PropertyType(True, IS_STR),
101-
"MaximumBatchingWindowInSeconds": PropertyType(False, is_type(int)),
102-
"MaximumRetryAttempts": PropertyType(False, is_type(int)),
103-
"BisectBatchOnFunctionError": PropertyType(False, is_type(bool)),
104-
"MaximumRecordAgeInSeconds": PropertyType(False, is_type(int)),
105-
"DestinationConfig": PropertyType(False, IS_DICT),
106-
"ParallelizationFactor": PropertyType(False, is_type(int)),
107-
"StartingPosition": PropertyType(False, IS_STR),
108-
"StartingPositionTimestamp": PassThroughProperty(False),
109-
"Topics": PropertyType(False, is_type(list)),
110-
"Queues": PropertyType(False, is_type(list)),
111-
"SourceAccessConfigurations": PropertyType(False, is_type(list)),
112-
"TumblingWindowInSeconds": PropertyType(False, is_type(int)),
113-
"FunctionResponseTypes": PropertyType(False, is_type(list)),
114-
"SelfManagedEventSource": PropertyType(False, IS_DICT),
115-
"FilterCriteria": PropertyType(False, IS_DICT),
116-
"AmazonManagedKafkaEventSourceConfig": PropertyType(False, IS_DICT),
117-
"SelfManagedKafkaEventSourceConfig": PropertyType(False, IS_DICT),
118-
"ScalingConfig": PropertyType(False, IS_DICT),
96+
"BatchSize": GeneratedProperty(),
97+
"Enabled": GeneratedProperty(),
98+
"EventSourceArn": GeneratedProperty(),
99+
"FunctionName": GeneratedProperty(),
100+
"MaximumBatchingWindowInSeconds": GeneratedProperty(),
101+
"MaximumRetryAttempts": GeneratedProperty(),
102+
"BisectBatchOnFunctionError": GeneratedProperty(),
103+
"MaximumRecordAgeInSeconds": GeneratedProperty(),
104+
"DestinationConfig": GeneratedProperty(),
105+
"ParallelizationFactor": GeneratedProperty(),
106+
"StartingPosition": GeneratedProperty(),
107+
"StartingPositionTimestamp": GeneratedProperty(),
108+
"Topics": GeneratedProperty(),
109+
"Queues": GeneratedProperty(),
110+
"SourceAccessConfigurations": GeneratedProperty(),
111+
"TumblingWindowInSeconds": GeneratedProperty(),
112+
"FunctionResponseTypes": GeneratedProperty(),
113+
"SelfManagedEventSource": GeneratedProperty(),
114+
"FilterCriteria": GeneratedProperty(),
115+
"AmazonManagedKafkaEventSourceConfig": GeneratedProperty(),
116+
"SelfManagedKafkaEventSourceConfig": GeneratedProperty(),
117+
"ScalingConfig": GeneratedProperty(),
119118
}
120119

121120
runtime_attrs = {"name": lambda self: ref(self.logical_id)}
@@ -124,24 +123,24 @@ class LambdaEventSourceMapping(Resource):
124123
class LambdaPermission(Resource):
125124
resource_type = "AWS::Lambda::Permission"
126125
property_types = {
127-
"Action": PropertyType(True, IS_STR),
128-
"FunctionName": PropertyType(True, IS_STR),
129-
"Principal": PropertyType(True, IS_STR),
130-
"SourceAccount": PropertyType(False, IS_STR),
131-
"SourceArn": PropertyType(False, IS_STR),
132-
"EventSourceToken": PropertyType(False, IS_STR),
133-
"FunctionUrlAuthType": PropertyType(False, IS_STR),
126+
"Action": GeneratedProperty(),
127+
"FunctionName": GeneratedProperty(),
128+
"Principal": GeneratedProperty(),
129+
"SourceAccount": GeneratedProperty(),
130+
"SourceArn": GeneratedProperty(),
131+
"EventSourceToken": GeneratedProperty(),
132+
"FunctionUrlAuthType": GeneratedProperty(),
134133
}
135134

136135

137136
class LambdaEventInvokeConfig(Resource):
138137
resource_type = "AWS::Lambda::EventInvokeConfig"
139138
property_types = {
140-
"DestinationConfig": PropertyType(False, IS_DICT),
141-
"FunctionName": PropertyType(True, IS_STR),
142-
"MaximumEventAgeInSeconds": PropertyType(False, is_type(int)),
143-
"MaximumRetryAttempts": PropertyType(False, is_type(int)),
144-
"Qualifier": PropertyType(True, IS_STR),
139+
"DestinationConfig": GeneratedProperty(),
140+
"FunctionName": GeneratedProperty(),
141+
"MaximumEventAgeInSeconds": GeneratedProperty(),
142+
"MaximumRetryAttempts": GeneratedProperty(),
143+
"Qualifier": GeneratedProperty(),
145144
}
146145

147146

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

151150
resource_type = "AWS::Lambda::LayerVersion"
152151
property_types = {
153-
"Content": PropertyType(True, IS_DICT),
154-
"Description": PropertyType(False, IS_STR),
155-
"LayerName": PropertyType(False, IS_STR),
156-
"CompatibleArchitectures": PropertyType(False, list_of(one_of(IS_STR, IS_DICT))),
157-
"CompatibleRuntimes": PropertyType(False, list_of(one_of(IS_STR, IS_DICT))),
158-
"LicenseInfo": PropertyType(False, IS_STR),
152+
"Content": GeneratedProperty(),
153+
"Description": GeneratedProperty(),
154+
"LayerName": GeneratedProperty(),
155+
"CompatibleArchitectures": GeneratedProperty(),
156+
"CompatibleRuntimes": GeneratedProperty(),
157+
"LicenseInfo": GeneratedProperty(),
159158
}
160159

161160
Content: Dict[str, Any]
@@ -171,7 +170,7 @@ class LambdaLayerVersion(Resource):
171170
class LambdaUrl(Resource):
172171
resource_type = "AWS::Lambda::Url"
173172
property_types = {
174-
"TargetFunctionArn": PropertyType(True, one_of(IS_STR, IS_DICT)),
175-
"AuthType": PropertyType(True, IS_STR),
176-
"Cors": PropertyType(False, IS_DICT),
173+
"TargetFunctionArn": GeneratedProperty(),
174+
"AuthType": GeneratedProperty(),
175+
"Cors": GeneratedProperty(),
177176
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Resources:
2+
MinimalFunction:
3+
Type: AWS::Serverless::Function
4+
Properties:
5+
CodeUri: s3://sam-demo-bucket/hello.zip
6+
Handler: hello.handler
7+
Runtime: python3.7
8+
MemorySize: '700'
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"Resources": {
3+
"MinimalFunction": {
4+
"Properties": {
5+
"Code": {
6+
"S3Bucket": "sam-demo-bucket",
7+
"S3Key": "hello.zip"
8+
},
9+
"Handler": "hello.handler",
10+
"MemorySize": "700",
11+
"Role": {
12+
"Fn::GetAtt": [
13+
"MinimalFunctionRole",
14+
"Arn"
15+
]
16+
},
17+
"Runtime": "python3.7",
18+
"Tags": [
19+
{
20+
"Key": "lambda:createdBy",
21+
"Value": "SAM"
22+
}
23+
]
24+
},
25+
"Type": "AWS::Lambda::Function"
26+
},
27+
"MinimalFunctionRole": {
28+
"Properties": {
29+
"AssumeRolePolicyDocument": {
30+
"Statement": [
31+
{
32+
"Action": [
33+
"sts:AssumeRole"
34+
],
35+
"Effect": "Allow",
36+
"Principal": {
37+
"Service": [
38+
"lambda.amazonaws.com"
39+
]
40+
}
41+
}
42+
],
43+
"Version": "2012-10-17"
44+
},
45+
"ManagedPolicyArns": [
46+
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
47+
],
48+
"Tags": [
49+
{
50+
"Key": "lambda:createdBy",
51+
"Value": "SAM"
52+
}
53+
]
54+
},
55+
"Type": "AWS::IAM::Role"
56+
}
57+
}
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"Resources": {
3+
"MinimalFunction": {
4+
"Properties": {
5+
"Code": {
6+
"S3Bucket": "sam-demo-bucket",
7+
"S3Key": "hello.zip"
8+
},
9+
"Handler": "hello.handler",
10+
"MemorySize": "700",
11+
"Role": {
12+
"Fn::GetAtt": [
13+
"MinimalFunctionRole",
14+
"Arn"
15+
]
16+
},
17+
"Runtime": "python3.7",
18+
"Tags": [
19+
{
20+
"Key": "lambda:createdBy",
21+
"Value": "SAM"
22+
}
23+
]
24+
},
25+
"Type": "AWS::Lambda::Function"
26+
},
27+
"MinimalFunctionRole": {
28+
"Properties": {
29+
"AssumeRolePolicyDocument": {
30+
"Statement": [
31+
{
32+
"Action": [
33+
"sts:AssumeRole"
34+
],
35+
"Effect": "Allow",
36+
"Principal": {
37+
"Service": [
38+
"lambda.amazonaws.com"
39+
]
40+
}
41+
}
42+
],
43+
"Version": "2012-10-17"
44+
},
45+
"ManagedPolicyArns": [
46+
"arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
47+
],
48+
"Tags": [
49+
{
50+
"Key": "lambda:createdBy",
51+
"Value": "SAM"
52+
}
53+
]
54+
},
55+
"Type": "AWS::IAM::Role"
56+
}
57+
}
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"Resources": {
3+
"MinimalFunction": {
4+
"Properties": {
5+
"Code": {
6+
"S3Bucket": "sam-demo-bucket",
7+
"S3Key": "hello.zip"
8+
},
9+
"Handler": "hello.handler",
10+
"MemorySize": "700",
11+
"Role": {
12+
"Fn::GetAtt": [
13+
"MinimalFunctionRole",
14+
"Arn"
15+
]
16+
},
17+
"Runtime": "python3.7",
18+
"Tags": [
19+
{
20+
"Key": "lambda:createdBy",
21+
"Value": "SAM"
22+
}
23+
]
24+
},
25+
"Type": "AWS::Lambda::Function"
26+
},
27+
"MinimalFunctionRole": {
28+
"Properties": {
29+
"AssumeRolePolicyDocument": {
30+
"Statement": [
31+
{
32+
"Action": [
33+
"sts:AssumeRole"
34+
],
35+
"Effect": "Allow",
36+
"Principal": {
37+
"Service": [
38+
"lambda.amazonaws.com"
39+
]
40+
}
41+
}
42+
],
43+
"Version": "2012-10-17"
44+
},
45+
"ManagedPolicyArns": [
46+
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
47+
],
48+
"Tags": [
49+
{
50+
"Key": "lambda:createdBy",
51+
"Value": "SAM"
52+
}
53+
]
54+
},
55+
"Type": "AWS::IAM::Role"
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)