From 1ba02e369a3f7c91cf7f81111e21cd8c865627cc Mon Sep 17 00:00:00 2001 From: Tony Sellitti Date: Tue, 12 Feb 2019 21:42:52 -0500 Subject: [PATCH 1/3] Enhance CompatibleRuntimes property of AWS::Serverless::LayerVersion Allow it to accept a !Ref to a String whereas currently it requires a List --- samtranslator/model/lambda_.py | 2 +- samtranslator/model/sam_resources.py | 4 ++- .../input/layers_with_intrinsics.yaml | 3 +++ .../output/aws-cn/layers_with_intrinsics.json | 26 ++++++++++++++----- .../aws-us-gov/layers_with_intrinsics.json | 26 ++++++++++++++----- .../output/layers_with_intrinsics.json | 26 ++++++++++++++----- 6 files changed, 67 insertions(+), 20 deletions(-) diff --git a/samtranslator/model/lambda_.py b/samtranslator/model/lambda_.py index e4603adf70..52de4a457c 100644 --- a/samtranslator/model/lambda_.py +++ b/samtranslator/model/lambda_.py @@ -94,7 +94,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()) } diff --git a/samtranslator/model/sam_resources.py b/samtranslator/model/sam_resources.py index a643b35fde..55628a7f36 100644 --- a/samtranslator/model/sam_resources.py +++ b/samtranslator/model/sam_resources.py @@ -604,7 +604,9 @@ 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(is_str())), + 'CompatibleRuntimes': PropertyType(False, list_of(one_of(is_str(), is_type(dict)))), +## 'CompatibleRuntimes': PropertyType(False, one_of(is_str(), list_of(one_of(is_str(), is_type(dict), is_type(dict))))), 'LicenseInfo': PropertyType(False, is_str()), 'RetentionPolicy': PropertyType(False, is_str()) } diff --git a/tests/translator/input/layers_with_intrinsics.yaml b/tests/translator/input/layers_with_intrinsics.yaml index 65a4127240..aecf2fbb3d 100644 --- a/tests/translator/input/layers_with_intrinsics.yaml +++ b/tests/translator/input/layers_with_intrinsics.yaml @@ -7,6 +7,9 @@ Parameters: Default: MIT-0 License LayerRuntimeList: Type: CommaDelimitedList + LayerRuntimeString: + Type: String + Default: nodejs8.10 Resources: LayerWithLicenseIntrinsic: diff --git a/tests/translator/output/aws-cn/layers_with_intrinsics.json b/tests/translator/output/aws-cn/layers_with_intrinsics.json index 6d88f83301..7f6154b54e 100644 --- a/tests/translator/output/aws-cn/layers_with_intrinsics.json +++ b/tests/translator/output/aws-cn/layers_with_intrinsics.json @@ -11,14 +11,14 @@ "Default": "SomeLayerName", "Type": "String" } - }, + }, "Resources": { "LayerWithNameIntrinsiccf8baed8b9": { "DeletionPolicy": "Retain", "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, "LayerName": "SomeLayerName" @@ -29,12 +29,26 @@ "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - }, - "LayerName": "LayerWithRuntimesIntrinsic", + }, + "LayerName": "LayerWithRuntimesStringIntrinsic", + "CompatibleRuntimes": { + "Ref": "LayerRuntimeString" + } + } + }, + "LayerWithRuntimesIntrinsic1ec42e9de6": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", + "Properties": { + "Content": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "layer.zip" + }, + "LayerName": "LayerWithRuntimesIntrinsic", "CompatibleRuntimes": { - "Ref": "LayerRuntimeList" + "Fn::Ref:": "LayerRuntimeList" } } }, diff --git a/tests/translator/output/aws-us-gov/layers_with_intrinsics.json b/tests/translator/output/aws-us-gov/layers_with_intrinsics.json index 6d88f83301..7f6154b54e 100644 --- a/tests/translator/output/aws-us-gov/layers_with_intrinsics.json +++ b/tests/translator/output/aws-us-gov/layers_with_intrinsics.json @@ -11,14 +11,14 @@ "Default": "SomeLayerName", "Type": "String" } - }, + }, "Resources": { "LayerWithNameIntrinsiccf8baed8b9": { "DeletionPolicy": "Retain", "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, "LayerName": "SomeLayerName" @@ -29,12 +29,26 @@ "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - }, - "LayerName": "LayerWithRuntimesIntrinsic", + }, + "LayerName": "LayerWithRuntimesStringIntrinsic", + "CompatibleRuntimes": { + "Ref": "LayerRuntimeString" + } + } + }, + "LayerWithRuntimesIntrinsic1ec42e9de6": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", + "Properties": { + "Content": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "layer.zip" + }, + "LayerName": "LayerWithRuntimesIntrinsic", "CompatibleRuntimes": { - "Ref": "LayerRuntimeList" + "Fn::Ref:": "LayerRuntimeList" } } }, diff --git a/tests/translator/output/layers_with_intrinsics.json b/tests/translator/output/layers_with_intrinsics.json index 6d88f83301..7f6154b54e 100644 --- a/tests/translator/output/layers_with_intrinsics.json +++ b/tests/translator/output/layers_with_intrinsics.json @@ -11,14 +11,14 @@ "Default": "SomeLayerName", "Type": "String" } - }, + }, "Resources": { "LayerWithNameIntrinsiccf8baed8b9": { "DeletionPolicy": "Retain", "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, "LayerName": "SomeLayerName" @@ -29,12 +29,26 @@ "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - }, - "LayerName": "LayerWithRuntimesIntrinsic", + }, + "LayerName": "LayerWithRuntimesStringIntrinsic", + "CompatibleRuntimes": { + "Ref": "LayerRuntimeString" + } + } + }, + "LayerWithRuntimesIntrinsic1ec42e9de6": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", + "Properties": { + "Content": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "layer.zip" + }, + "LayerName": "LayerWithRuntimesIntrinsic", "CompatibleRuntimes": { - "Ref": "LayerRuntimeList" + "Fn::Ref:": "LayerRuntimeList" } } }, From 9c9eda00e9dc203f432c1b190ca68acdbe7dfc89 Mon Sep 17 00:00:00 2001 From: Tony Sellitti Date: Wed, 20 Feb 2019 09:50:10 -0500 Subject: [PATCH 2/3] Fix PR Review items and add a further test --- samtranslator/model/sam_resources.py | 4 +--- tests/translator/input/layers_with_intrinsics.yaml | 5 ++++- .../output/aws-cn/layers_with_intrinsics.json | 10 +++++----- .../output/aws-us-gov/layers_with_intrinsics.json | 10 +++++----- tests/translator/output/layers_with_intrinsics.json | 10 +++++----- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/samtranslator/model/sam_resources.py b/samtranslator/model/sam_resources.py index 55628a7f36..3e87fd1fc1 100644 --- a/samtranslator/model/sam_resources.py +++ b/samtranslator/model/sam_resources.py @@ -604,9 +604,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)))), -## 'CompatibleRuntimes': PropertyType(False, one_of(is_str(), list_of(one_of(is_str(), is_type(dict), is_type(dict))))), + 'CompatibleRuntimes': PropertyType(False, list_of( one_of( is_str(), is_type(dict) ) )), 'LicenseInfo': PropertyType(False, is_str()), 'RetentionPolicy': PropertyType(False, is_str()) } diff --git a/tests/translator/input/layers_with_intrinsics.yaml b/tests/translator/input/layers_with_intrinsics.yaml index aecf2fbb3d..b2ecfd40c5 100644 --- a/tests/translator/input/layers_with_intrinsics.yaml +++ b/tests/translator/input/layers_with_intrinsics.yaml @@ -7,7 +7,10 @@ Parameters: Default: MIT-0 License LayerRuntimeList: Type: CommaDelimitedList - LayerRuntimeString: + LayerRuntimeString1: + Type: String + Default: nodejs6.10 + LayerRuntimeString2: Type: String Default: nodejs8.10 diff --git a/tests/translator/output/aws-cn/layers_with_intrinsics.json b/tests/translator/output/aws-cn/layers_with_intrinsics.json index 7f6154b54e..2d62dde13d 100644 --- a/tests/translator/output/aws-cn/layers_with_intrinsics.json +++ b/tests/translator/output/aws-cn/layers_with_intrinsics.json @@ -34,11 +34,11 @@ }, "LayerName": "LayerWithRuntimesStringIntrinsic", "CompatibleRuntimes": { - "Ref": "LayerRuntimeString" + "Ref": "LayerRuntimeString1" } } }, - "LayerWithRuntimesIntrinsic1ec42e9de6": { + "LayerWithLicenseIntrinsic16287c50c8": { "DeletionPolicy": "Retain", "Type": "AWS::Lambda::LayerVersion", "Properties": { @@ -46,9 +46,9 @@ "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithRuntimesIntrinsic", - "CompatibleRuntimes": { - "Fn::Ref:": "LayerRuntimeList" + "LayerName": "LayerWithLicenseIntrinsic", + "LicenseInfo": { + "Ref": "LayerLicenseInfo" } } }, diff --git a/tests/translator/output/aws-us-gov/layers_with_intrinsics.json b/tests/translator/output/aws-us-gov/layers_with_intrinsics.json index 7f6154b54e..2d62dde13d 100644 --- a/tests/translator/output/aws-us-gov/layers_with_intrinsics.json +++ b/tests/translator/output/aws-us-gov/layers_with_intrinsics.json @@ -34,11 +34,11 @@ }, "LayerName": "LayerWithRuntimesStringIntrinsic", "CompatibleRuntimes": { - "Ref": "LayerRuntimeString" + "Ref": "LayerRuntimeString1" } } }, - "LayerWithRuntimesIntrinsic1ec42e9de6": { + "LayerWithLicenseIntrinsic16287c50c8": { "DeletionPolicy": "Retain", "Type": "AWS::Lambda::LayerVersion", "Properties": { @@ -46,9 +46,9 @@ "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithRuntimesIntrinsic", - "CompatibleRuntimes": { - "Fn::Ref:": "LayerRuntimeList" + "LayerName": "LayerWithLicenseIntrinsic", + "LicenseInfo": { + "Ref": "LayerLicenseInfo" } } }, diff --git a/tests/translator/output/layers_with_intrinsics.json b/tests/translator/output/layers_with_intrinsics.json index 7f6154b54e..2d62dde13d 100644 --- a/tests/translator/output/layers_with_intrinsics.json +++ b/tests/translator/output/layers_with_intrinsics.json @@ -34,11 +34,11 @@ }, "LayerName": "LayerWithRuntimesStringIntrinsic", "CompatibleRuntimes": { - "Ref": "LayerRuntimeString" + "Ref": "LayerRuntimeString1" } } }, - "LayerWithRuntimesIntrinsic1ec42e9de6": { + "LayerWithLicenseIntrinsic16287c50c8": { "DeletionPolicy": "Retain", "Type": "AWS::Lambda::LayerVersion", "Properties": { @@ -46,9 +46,9 @@ "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithRuntimesIntrinsic", - "CompatibleRuntimes": { - "Fn::Ref:": "LayerRuntimeList" + "LayerName": "LayerWithLicenseIntrinsic", + "LicenseInfo": { + "Ref": "LayerLicenseInfo" } } }, From b97ec4f91f019e342281361bc3df30d15648e0fb Mon Sep 17 00:00:00 2001 From: Tony Sellitti Date: Tue, 26 Feb 2019 19:46:39 -0500 Subject: [PATCH 3/3] Minor linter bugfix --- samtranslator/model/sam_resources.py | 2 +- .../output/aws-cn/layers_with_intrinsics.json | 49 ++++++++----------- .../aws-us-gov/layers_with_intrinsics.json | 48 ++++++++---------- .../output/layers_with_intrinsics.json | 48 ++++++++---------- 4 files changed, 64 insertions(+), 83 deletions(-) diff --git a/samtranslator/model/sam_resources.py b/samtranslator/model/sam_resources.py index 3e87fd1fc1..10806272ca 100644 --- a/samtranslator/model/sam_resources.py +++ b/samtranslator/model/sam_resources.py @@ -604,7 +604,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( one_of( is_str(), is_type(dict) ) )), + 'CompatibleRuntimes': PropertyType(False, list_of(one_of(is_str(), is_type(dict)))), 'LicenseInfo': PropertyType(False, is_str()), 'RetentionPolicy': PropertyType(False, is_str()) } diff --git a/tests/translator/output/aws-cn/layers_with_intrinsics.json b/tests/translator/output/aws-cn/layers_with_intrinsics.json index 2d62dde13d..066cd69f8f 100644 --- a/tests/translator/output/aws-cn/layers_with_intrinsics.json +++ b/tests/translator/output/aws-cn/layers_with_intrinsics.json @@ -1,44 +1,52 @@ { "Parameters": { "LayerLicenseInfo": { - "Default": "MIT-0 License", + "Default": "MIT-0 License", "Type": "String" - }, + }, "LayerRuntimeList": { "Type": "CommaDelimitedList" - }, + }, "LayerNameParam": { - "Default": "SomeLayerName", + "Default": "SomeLayerName", + "Type": "String" + }, + "LayerRuntimeString1": { + "Default": "nodejs6.10", + "Type": "String" + }, + "LayerRuntimeString2": { + "Default": "nodejs8.10", "Type": "String" } }, "Resources": { "LayerWithNameIntrinsiccf8baed8b9": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - }, + }, "LayerName": "SomeLayerName" } - }, + }, "LayerWithRuntimesIntrinsic1a006faa85": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithRuntimesStringIntrinsic", + "LayerName": "LayerWithRuntimesIntrinsic", "CompatibleRuntimes": { - "Ref": "LayerRuntimeString1" + "Ref": "LayerRuntimeList" } } }, - "LayerWithLicenseIntrinsic16287c50c8": { + "LayerWithLicenseIntrinsic965c8d0c9b": { "DeletionPolicy": "Retain", "Type": "AWS::Lambda::LayerVersion", "Properties": { @@ -47,23 +55,8 @@ "S3Key": "layer.zip" }, "LayerName": "LayerWithLicenseIntrinsic", - "LicenseInfo": { - "Ref": "LayerLicenseInfo" - } - } - }, - "LayerWithLicenseIntrinsic965c8d0c9b": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", - "Properties": { - "Content": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "layer.zip" - }, - "LayerName": "LayerWithLicenseIntrinsic", "LicenseInfo": "MIT-0 License" } } } } - diff --git a/tests/translator/output/aws-us-gov/layers_with_intrinsics.json b/tests/translator/output/aws-us-gov/layers_with_intrinsics.json index 2d62dde13d..d40c1a479d 100644 --- a/tests/translator/output/aws-us-gov/layers_with_intrinsics.json +++ b/tests/translator/output/aws-us-gov/layers_with_intrinsics.json @@ -1,44 +1,52 @@ { "Parameters": { "LayerLicenseInfo": { - "Default": "MIT-0 License", + "Default": "MIT-0 License", "Type": "String" - }, + }, "LayerRuntimeList": { "Type": "CommaDelimitedList" - }, + }, "LayerNameParam": { - "Default": "SomeLayerName", + "Default": "SomeLayerName", + "Type": "String" + }, + "LayerRuntimeString1": { + "Default": "nodejs6.10", + "Type": "String" + }, + "LayerRuntimeString2": { + "Default": "nodejs8.10", "Type": "String" } }, "Resources": { "LayerWithNameIntrinsiccf8baed8b9": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - }, + }, "LayerName": "SomeLayerName" } - }, + }, "LayerWithRuntimesIntrinsic1a006faa85": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithRuntimesStringIntrinsic", + "LayerName": "LayerWithRuntimesIntrinsic", "CompatibleRuntimes": { - "Ref": "LayerRuntimeString1" + "Ref": "LayerRuntimeList" } } }, - "LayerWithLicenseIntrinsic16287c50c8": { + "LayerWithLicenseIntrinsic965c8d0c9b": { "DeletionPolicy": "Retain", "Type": "AWS::Lambda::LayerVersion", "Properties": { @@ -47,20 +55,6 @@ "S3Key": "layer.zip" }, "LayerName": "LayerWithLicenseIntrinsic", - "LicenseInfo": { - "Ref": "LayerLicenseInfo" - } - } - }, - "LayerWithLicenseIntrinsic965c8d0c9b": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", - "Properties": { - "Content": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "layer.zip" - }, - "LayerName": "LayerWithLicenseIntrinsic", "LicenseInfo": "MIT-0 License" } } diff --git a/tests/translator/output/layers_with_intrinsics.json b/tests/translator/output/layers_with_intrinsics.json index 2d62dde13d..d40c1a479d 100644 --- a/tests/translator/output/layers_with_intrinsics.json +++ b/tests/translator/output/layers_with_intrinsics.json @@ -1,44 +1,52 @@ { "Parameters": { "LayerLicenseInfo": { - "Default": "MIT-0 License", + "Default": "MIT-0 License", "Type": "String" - }, + }, "LayerRuntimeList": { "Type": "CommaDelimitedList" - }, + }, "LayerNameParam": { - "Default": "SomeLayerName", + "Default": "SomeLayerName", + "Type": "String" + }, + "LayerRuntimeString1": { + "Default": "nodejs6.10", + "Type": "String" + }, + "LayerRuntimeString2": { + "Default": "nodejs8.10", "Type": "String" } }, "Resources": { "LayerWithNameIntrinsiccf8baed8b9": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - }, + }, "LayerName": "SomeLayerName" } - }, + }, "LayerWithRuntimesIntrinsic1a006faa85": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithRuntimesStringIntrinsic", + "LayerName": "LayerWithRuntimesIntrinsic", "CompatibleRuntimes": { - "Ref": "LayerRuntimeString1" + "Ref": "LayerRuntimeList" } } }, - "LayerWithLicenseIntrinsic16287c50c8": { + "LayerWithLicenseIntrinsic965c8d0c9b": { "DeletionPolicy": "Retain", "Type": "AWS::Lambda::LayerVersion", "Properties": { @@ -47,20 +55,6 @@ "S3Key": "layer.zip" }, "LayerName": "LayerWithLicenseIntrinsic", - "LicenseInfo": { - "Ref": "LayerLicenseInfo" - } - } - }, - "LayerWithLicenseIntrinsic965c8d0c9b": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", - "Properties": { - "Content": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "layer.zip" - }, - "LayerName": "LayerWithLicenseIntrinsic", "LicenseInfo": "MIT-0 License" } }