Skip to content
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
2 changes: 1 addition & 1 deletion samtranslator/model/lambda_.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class LambdaLayerVersion(Resource):
"Content": PropertyType(True, is_type(dict)),
"Description": PropertyType(False, is_str()),
"LayerName": PropertyType(False, is_str()),
"CompatibleRuntimes": PropertyType(False, list_of(is_str())),
"CompatibleRuntimes": PropertyType(False, list_of(one_of(is_str(), is_type(dict)))),
"LicenseInfo": PropertyType(False, is_str()),
}

Expand Down
6 changes: 3 additions & 3 deletions samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class SamFunction(SamResourceMacro):
"VpcConfig": PropertyType(False, is_type(dict)),
"Role": PropertyType(False, is_str()),
"AssumeRolePolicyDocument": PropertyType(False, is_type(dict)),
"Policies": PropertyType(False, one_of(is_str(), list_of(one_of(is_str(), is_type(dict), is_type(dict))))),
"Policies": PropertyType(False, one_of(is_str(), is_type(dict), list_of(one_of(is_str(), is_type(dict))))),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Is this just a reorder? It is hard to tell from the diff.

Copy link
Contributor Author

@wchengru wchengru Aug 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a typo inside one_of(is_str(), is_type(dict), is_type(dict)). Two repeated is_type(dict) are meaningless. I checked property "Policies" in AWS::Serverless::Function, the acceptable type is String | List | Map, so this property should be one of the three types: is_str(), is_type(dict), or list of one_of(is_str(), is_type(dict)). I moved out the extra is_type(dict) to let it also allow maps.

"PermissionsBoundary": PropertyType(False, is_str()),
"Environment": PropertyType(False, dict_of(is_str(), is_type(dict))),
"Events": PropertyType(False, dict_of(is_str(), is_type(dict))),
Expand Down Expand Up @@ -1015,7 +1015,7 @@ class SamLayerVersion(SamResourceMacro):
"LayerName": PropertyType(False, one_of(is_str(), is_type(dict))),
"Description": PropertyType(False, is_str()),
"ContentUri": PropertyType(True, one_of(is_str(), is_type(dict))),
"CompatibleRuntimes": PropertyType(False, list_of(is_str())),
"CompatibleRuntimes": PropertyType(False, list_of(one_of(is_str(), is_type(dict)))),
"LicenseInfo": PropertyType(False, is_str()),
"RetentionPolicy": PropertyType(False, is_str()),
}
Expand Down Expand Up @@ -1120,7 +1120,7 @@ class SamStateMachine(SamResourceMacro):
"Name": PropertyType(False, is_str()),
"Type": PropertyType(False, is_str()),
"Tags": PropertyType(False, is_type(dict)),
"Policies": PropertyType(False, one_of(is_str(), list_of(one_of(is_str(), is_type(dict), is_type(dict))))),
"Policies": PropertyType(False, one_of(is_str(), is_type(dict), list_of(one_of(is_str(), is_type(dict))))),
}
event_resolver = ResourceTypeResolver(samtranslator.model.stepfunctions.events,)

Expand Down
19 changes: 19 additions & 0 deletions tests/translator/input/layers_with_intrinsics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Parameters:
Default: MIT-0 License
LayerRuntimeList:
Type: CommaDelimitedList
LayerRuntimeRefString:
Type: String
Default: SomeRuntimeName

Resources:
LayerWithLicenseIntrinsic:
Expand All @@ -22,6 +25,21 @@ Resources:
CompatibleRuntimes:
Ref: LayerRuntimeList

LayerWithSingleListRefRuntimesIntrinsic:
Type: 'AWS::Serverless::LayerVersion'
Properties:
ContentUri: s3://sam-demo-bucket/layer.zip
CompatibleRuntimes:
- Ref: LayerRuntimeRefString

LayerWithMixedListRefRuntimesIntrinsic:
Type: 'AWS::Serverless::LayerVersion'
Properties:
ContentUri: s3://sam-demo-bucket/layer.zip
CompatibleRuntimes:
- Ref: LayerRuntimeString
- 'SomeRuntimeNameString'

LayerWithNameIntrinsic:
Type: AWS::Serverless::LayerVersion
Properties:
Expand All @@ -46,3 +64,4 @@ Resources:
ContentUri: s3://sam-demo-bucket/layer.zip
LayerName: !Sub 'layer-${AWS::Region}'


37 changes: 37 additions & 0 deletions tests/translator/output/aws-cn/layers_with_intrinsics.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
"LayerNameParam": {
"Default": "SomeLayerName",
"Type": "String"
},
"LayerRuntimeRefString": {
"Default": "SomeRuntimeName",
"Type": "String"
}
},
"Resources": {
Expand Down Expand Up @@ -62,6 +66,39 @@
}
}
},
"LayerWithSingleListRefRuntimesIntrinsic9d7a72f24a": {
"DeletionPolicy": "Retain",
"Properties": {
"CompatibleRuntimes": [
{
"Ref": "LayerRuntimeRefString"
}
],
"Content": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "layer.zip"
},
"LayerName": "LayerWithSingleListRefRuntimesIntrinsic"
},
"Type": "AWS::Lambda::LayerVersion"
},
"LayerWithMixedListRefRuntimesIntrinsic71fd80f592": {
"DeletionPolicy": "Retain",
"Properties": {
"CompatibleRuntimes": [
{
"Ref": "LayerRuntimeString"
},
"SomeRuntimeNameString"
],
"Content": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "layer.zip"
},
"LayerName": "LayerWithMixedListRefRuntimesIntrinsic"
},
"Type": "AWS::Lambda::LayerVersion"
},
"LayerWithLicenseIntrinsic965c8d0c9b": {
"DeletionPolicy": "Retain",
"Type": "AWS::Lambda::LayerVersion",
Expand Down
37 changes: 37 additions & 0 deletions tests/translator/output/aws-us-gov/layers_with_intrinsics.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
"LayerNameParam": {
"Default": "SomeLayerName",
"Type": "String"
},
"LayerRuntimeRefString": {
"Default": "SomeRuntimeName",
"Type": "String"
}
},
"Resources": {
Expand Down Expand Up @@ -62,6 +66,39 @@
}
}
},
"LayerWithSingleListRefRuntimesIntrinsic9d7a72f24a": {
"DeletionPolicy": "Retain",
"Properties": {
"CompatibleRuntimes": [
{
"Ref": "LayerRuntimeRefString"
}
],
"Content": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "layer.zip"
},
"LayerName": "LayerWithSingleListRefRuntimesIntrinsic"
},
"Type": "AWS::Lambda::LayerVersion"
},
"LayerWithMixedListRefRuntimesIntrinsic71fd80f592": {
"DeletionPolicy": "Retain",
"Properties": {
"CompatibleRuntimes": [
{
"Ref": "LayerRuntimeString"
},
"SomeRuntimeNameString"
],
"Content": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "layer.zip"
},
"LayerName": "LayerWithMixedListRefRuntimesIntrinsic"
},
"Type": "AWS::Lambda::LayerVersion"
},
"LayerWithLicenseIntrinsic965c8d0c9b": {
"DeletionPolicy": "Retain",
"Type": "AWS::Lambda::LayerVersion",
Expand Down
37 changes: 37 additions & 0 deletions tests/translator/output/layers_with_intrinsics.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
"LayerNameParam": {
"Default": "SomeLayerName",
"Type": "String"
},
"LayerRuntimeRefString": {
"Default": "SomeRuntimeName",
"Type": "String"
}
},
"Resources": {
Expand Down Expand Up @@ -62,6 +66,39 @@
}
}
},
"LayerWithSingleListRefRuntimesIntrinsic9d7a72f24a": {
"DeletionPolicy": "Retain",
"Properties": {
"CompatibleRuntimes": [
{
"Ref": "LayerRuntimeRefString"
}
],
"Content": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "layer.zip"
},
"LayerName": "LayerWithSingleListRefRuntimesIntrinsic"
},
"Type": "AWS::Lambda::LayerVersion"
},
"LayerWithMixedListRefRuntimesIntrinsic71fd80f592": {
"DeletionPolicy": "Retain",
"Properties": {
"CompatibleRuntimes": [
{
"Ref": "LayerRuntimeString"
},
"SomeRuntimeNameString"
],
"Content": {
"S3Bucket": "sam-demo-bucket",
"S3Key": "layer.zip"
},
"LayerName": "LayerWithMixedListRefRuntimesIntrinsic"
},
"Type": "AWS::Lambda::LayerVersion"
},
"LayerWithLicenseIntrinsic965c8d0c9b": {
"DeletionPolicy": "Retain",
"Type": "AWS::Lambda::LayerVersion",
Expand Down