Skip to content

Commit

Permalink
fix: Enhance CompatibleRuntimes property of AWS::Serverless::LayerVer…
Browse files Browse the repository at this point in the history
…sion (#1683)
  • Loading branch information
wchengru authored Aug 21, 2020
1 parent 8b3ea4f commit ed2f24e
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 4 deletions.
2 changes: 1 addition & 1 deletion samtranslator/model/lambda_.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,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))))),
"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

0 comments on commit ed2f24e

Please sign in to comment.