diff --git a/samcli/lib/bootstrap/nested_stack/nested_stack_builder.py b/samcli/lib/bootstrap/nested_stack/nested_stack_builder.py index a668226bd1..0f2ca1f753 100644 --- a/samcli/lib/bootstrap/nested_stack/nested_stack_builder.py +++ b/samcli/lib/bootstrap/nested_stack/nested_stack_builder.py @@ -30,12 +30,12 @@ def add_function( layer_contents_folder: str, function: Function, ) -> str: - layer_logical_id = self.get_layer_logical_id(function.name) - layer_name = self.get_layer_name(stack_name, function.name) + layer_logical_id = self.get_layer_logical_id(function.full_path) + layer_name = self.get_layer_name(stack_name, function.full_path) self.add_resource( layer_logical_id, - self._get_layer_dict(function.name, layer_name, layer_contents_folder, cast(str, function.runtime)), + self._get_layer_dict(function.full_path, layer_name, layer_contents_folder, cast(str, function.runtime)), ) self.add_output(layer_logical_id, {"Ref": layer_logical_id}) return layer_logical_id diff --git a/samcli/lib/bootstrap/nested_stack/nested_stack_manager.py b/samcli/lib/bootstrap/nested_stack/nested_stack_manager.py index 47823bb20f..eb38494772 100644 --- a/samcli/lib/bootstrap/nested_stack/nested_stack_manager.py +++ b/samcli/lib/bootstrap/nested_stack/nested_stack_manager.py @@ -114,9 +114,9 @@ def generate_auto_dependency_layer_stack(self) -> Dict: return template def _add_layer(self, dependencies_dir: str, function: Function, resources: Dict): - layer_logical_id = NestedStackBuilder.get_layer_logical_id(function.name) + layer_logical_id = NestedStackBuilder.get_layer_logical_id(function.full_path) layer_location = self.update_layer_folder( - self._build_dir, dependencies_dir, layer_logical_id, function.name, function.runtime + self._build_dir, dependencies_dir, layer_logical_id, function.full_path, function.runtime ) layer_output_key = self._nested_stack_builder.add_function(self._stack_name, layer_location, function) diff --git a/tests/integration/deploy/test_deploy_command.py b/tests/integration/deploy/test_deploy_command.py index 6551280f1c..3ed0caa606 100644 --- a/tests/integration/deploy/test_deploy_command.py +++ b/tests/integration/deploy/test_deploy_command.py @@ -1231,7 +1231,7 @@ def test_deploy_logs_warning_with_cdk_project(self, template_file): ) warning_message = bytes( - "Warning: CDK apps are not officially supported with this command.\n" + f"Warning: CDK apps are not officially supported with this command.{os.linesep}" "We recommend you use this alternative command: cdk deploy", encoding="utf-8", ) diff --git a/tests/integration/package/test_package_command_zip.py b/tests/integration/package/test_package_command_zip.py index 0b8785e0b4..05a0dc0ca2 100644 --- a/tests/integration/package/test_package_command_zip.py +++ b/tests/integration/package/test_package_command_zip.py @@ -613,7 +613,7 @@ def test_package_logs_warning_for_cdk_project(self, template_file): process_stdout = stdout.strip() warning_message = bytes( - "Warning: CDK apps are not officially supported with this command.\n" + f"Warning: CDK apps are not officially supported with this command.{os.linesep}" "We recommend you use this alternative command: cdk deploy", encoding="utf-8", ) diff --git a/tests/integration/testdata/package/aws-cloudformation-stack-child.yaml b/tests/integration/testdata/package/aws-cloudformation-stack-child.yaml new file mode 100644 index 0000000000..ac7963836f --- /dev/null +++ b/tests/integration/testdata/package/aws-cloudformation-stack-child.yaml @@ -0,0 +1,13 @@ +AWSTemplateFormatVersion : '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Description: Simple Rest API + +Resources: + MyRestApi: + Type: AWS::ApiGateway::RestApi + Properties: + BodyS3Location: ./openapi.json + Description: A test API + Name: MyRestAPI + Metadata: + SamResourceId: MyRestApi \ No newline at end of file diff --git a/tests/integration/testdata/package/aws-cloudformation-stack-regression.yaml b/tests/integration/testdata/package/aws-cloudformation-stack-regression.yaml new file mode 100644 index 0000000000..316b7c62ac --- /dev/null +++ b/tests/integration/testdata/package/aws-cloudformation-stack-regression.yaml @@ -0,0 +1,11 @@ +AWSTemplateFormatVersion : '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Description: Simple Stack + +Resources: + myStack: + Type: AWS::CloudFormation::Stack + Properties: + TemplateURL: ./aws-cloudformation-stack-child.yaml + Metadata: + SamResourceId: MyRestApi \ No newline at end of file diff --git a/tests/integration/testdata/package/aws-serverlessrepo-application_regression.yaml b/tests/integration/testdata/package/aws-serverlessrepo-application_regression.yaml new file mode 100644 index 0000000000..87917571ae --- /dev/null +++ b/tests/integration/testdata/package/aws-serverlessrepo-application_regression.yaml @@ -0,0 +1,27 @@ +AWSTemplateFormatVersion : '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Description: Sample ServerlessRepo Application + +Resources: + HelloWorldFunction: + Type: AWS::Serverless::Function + Properties: + Handler: main.handler + Runtime: python3.7 + CodeUri: . + Timeout: 600 + Metadata: + SamResourceId: MyRestApi + +Metadata: + AWS::ServerlessRepo::Application: + Name: my-app + Description: hello world + Author: user1 + SpdxLicenseId: Apache-2.0 + LicenseUrl: ./LICENSE.txt + ReadmeUrl: ./README.md + Labels: ['tests'] + HomePageUrl: https://github.com/user1/my-app-project + SemanticVersion: 1.0.1 + SourceCodeUrl: https://github.com/user1/my-app-project \ No newline at end of file diff --git a/tests/integration/testdata/sync/infra/after/Ruby/function/Gemfile b/tests/integration/testdata/sync/infra/after/Ruby/function/Gemfile index 2000ad3a89..f363756be8 100644 --- a/tests/integration/testdata/sync/infra/after/Ruby/function/Gemfile +++ b/tests/integration/testdata/sync/infra/after/Ruby/function/Gemfile @@ -2,4 +2,4 @@ source "https://rubygems.org" gem "ruby-statistics" -ruby '~> 2.5.0' +ruby '~> 2.7.5' diff --git a/tests/integration/testdata/sync/infra/after/Ruby/layer/Gemfile b/tests/integration/testdata/sync/infra/after/Ruby/layer/Gemfile index a76cdc43e5..93f90933be 100644 --- a/tests/integration/testdata/sync/infra/after/Ruby/layer/Gemfile +++ b/tests/integration/testdata/sync/infra/after/Ruby/layer/Gemfile @@ -1,3 +1,3 @@ source "https://rubygems.org" -ruby '~> 2.5.0' +ruby '~> 2.7.5' diff --git a/tests/integration/testdata/sync/infra/before/Ruby/function/Gemfile b/tests/integration/testdata/sync/infra/before/Ruby/function/Gemfile index 2000ad3a89..f363756be8 100644 --- a/tests/integration/testdata/sync/infra/before/Ruby/function/Gemfile +++ b/tests/integration/testdata/sync/infra/before/Ruby/function/Gemfile @@ -2,4 +2,4 @@ source "https://rubygems.org" gem "ruby-statistics" -ruby '~> 2.5.0' +ruby '~> 2.7.5' diff --git a/tests/integration/testdata/sync/infra/before/Ruby/layer/Gemfile b/tests/integration/testdata/sync/infra/before/Ruby/layer/Gemfile index a76cdc43e5..93f90933be 100644 --- a/tests/integration/testdata/sync/infra/before/Ruby/layer/Gemfile +++ b/tests/integration/testdata/sync/infra/before/Ruby/layer/Gemfile @@ -1,3 +1,3 @@ source "https://rubygems.org" -ruby '~> 2.5.0' +ruby '~> 2.7.5' diff --git a/tests/integration/testdata/sync/infra/template-ruby-after.yaml b/tests/integration/testdata/sync/infra/template-ruby-after.yaml index 7a50622960..dc869b1691 100644 --- a/tests/integration/testdata/sync/infra/template-ruby-after.yaml +++ b/tests/integration/testdata/sync/infra/template-ruby-after.yaml @@ -12,7 +12,7 @@ Resources: AutoPublishAlias: Hello1Alias CodeUri: after/Ruby/function/ Handler: app.lambda_handler - Runtime: ruby2.5 + Runtime: ruby2.7 Architectures: - x86_64 Layers: @@ -25,6 +25,6 @@ Resources: Description: Hello World Ruby Layer ContentUri: after/Ruby/layer/ CompatibleRuntimes: - - ruby2.5 + - ruby2.7 Metadata: - BuildMethod: ruby2.5 \ No newline at end of file + BuildMethod: ruby2.7 \ No newline at end of file diff --git a/tests/integration/testdata/sync/infra/template-ruby-before.yaml b/tests/integration/testdata/sync/infra/template-ruby-before.yaml index 5dfc0a72c5..f5c312b2cb 100644 --- a/tests/integration/testdata/sync/infra/template-ruby-before.yaml +++ b/tests/integration/testdata/sync/infra/template-ruby-before.yaml @@ -12,7 +12,7 @@ Resources: AutoPublishAlias: Hello1Alias CodeUri: before/Ruby/function/ Handler: app.lambda_handler - Runtime: ruby2.5 + Runtime: ruby2.7 Architectures: - x86_64 Layers: @@ -25,6 +25,6 @@ Resources: Description: Hello World Ruby Layer ContentUri: before/Ruby/layer/ CompatibleRuntimes: - - ruby2.5 + - ruby2.7 Metadata: - BuildMethod: ruby2.5 \ No newline at end of file + BuildMethod: ruby2.7 \ No newline at end of file diff --git a/tests/integration/validate/test_validate_command.py b/tests/integration/validate/test_validate_command.py index 22a79a269d..cba52002dd 100644 --- a/tests/integration/validate/test_validate_command.py +++ b/tests/integration/validate/test_validate_command.py @@ -82,7 +82,7 @@ def test_validate_logs_warning_for_cdk_project(self): output = command_result.stdout.decode("utf-8") warning_message = ( - "Warning: CDK apps are not officially supported with this command.\n" + f"Warning: CDK apps are not officially supported with this command.{os.linesep}" "We recommend you use this alternative command: cdk doctor" ) diff --git a/tests/regression/package/regression_package_base.py b/tests/regression/package/regression_package_base.py index be3db81358..eece11503e 100644 --- a/tests/regression/package/regression_package_base.py +++ b/tests/regression/package/regression_package_base.py @@ -85,7 +85,7 @@ def get_command_list( return command_list - def regression_check(self, args): + def regression_check(self, args, skip_sam_metadata=True): with tempfile.NamedTemporaryFile(delete=False) as output_template_file_sam: sam_command_list = self.get_command_list(output_template_file=output_template_file_sam.name, **args) process = Popen(sam_command_list, stdout=PIPE) @@ -119,5 +119,18 @@ def regression_check(self, args): else: output_sam = yaml_parse(output_sam) output_aws = yaml_parse(output_aws) + if skip_sam_metadata: + self._remove_sam_related_metadata(output_sam) self.assertEqual(output_sam, output_aws) + + def _remove_sam_related_metadata(self, output_sam): + if "Resources" not in output_sam: + return + for _, resource in output_sam.get("Resources", {}).items(): + if "Metadata" not in resource: + continue + resource.get("Metadata", {}).pop("SamResourceId", None) + resource.get("Metadata", {}).pop("SamNormalize", None) + if not resource.get("Metadata", {}): + resource.pop("Metadata") diff --git a/tests/regression/package/test_package_regression.py b/tests/regression/package/test_package_regression.py index 0bee228ff8..4045b88e50 100644 --- a/tests/regression/package/test_package_regression.py +++ b/tests/regression/package/test_package_regression.py @@ -22,37 +22,35 @@ def tearDown(self): @parameterized.expand( [ - "aws-serverless-api.yaml", - "aws-appsync-graphqlschema.yaml", - "aws-appsync-resolver.yaml", - "aws-appsync-functionconfiguration.yaml", - "aws-apigateway-restapi.yaml", - "aws-apigatewayv2-httpapi.yaml", - "aws-elasticbeanstalk-applicationversion.yaml", - "aws-cloudformation-stack.yaml", - "aws-serverlessrepo-application.yaml", + ("aws-serverless-api.yaml", True), + ("aws-appsync-graphqlschema.yaml", True), + ("aws-appsync-resolver.yaml", True), + ("aws-appsync-functionconfiguration.yaml", True), + ("aws-apigateway-restapi.yaml", True), + ("aws-elasticbeanstalk-applicationversion.yaml", True), + ("aws-cloudformation-stack-regression.yaml", False), + ("aws-cloudformation-stack-regression.yaml", False), ] ) - def test_package_with_output_template_file(self, template_file): + def test_package_with_output_template_file(self, template_file, skip_sam_metadata=False): arguments = {"s3_bucket": self.s3_bucket.name, "template_file": self.test_data_path.joinpath(template_file)} - self.regression_check(arguments) + self.regression_check(arguments, skip_sam_metadata) @parameterized.expand( [ - "aws-serverless-api.yaml", - "aws-appsync-graphqlschema.yaml", - "aws-appsync-resolver.yaml", - "aws-appsync-functionconfiguration.yaml", - "aws-apigateway-restapi.yaml", - "aws-apigatewayv2-httpapi.yaml", - "aws-elasticbeanstalk-applicationversion.yaml", - "aws-cloudformation-stack.yaml", - "aws-serverlessrepo-application.yaml", + ("aws-serverless-api.yaml", True), + ("aws-appsync-graphqlschema.yaml", True), + ("aws-appsync-resolver.yaml", True), + ("aws-appsync-functionconfiguration.yaml", True), + ("aws-apigateway-restapi.yaml", True), + ("aws-elasticbeanstalk-applicationversion.yaml", True), + ("aws-cloudformation-stack-regression.yaml", False), + ("aws-cloudformation-stack-regression.yaml", False), ] ) - def test_package_with_output_template_file_and_prefix(self, template_file): + def test_package_with_output_template_file_and_prefix(self, template_file, skip_sam_metadata=False): arguments = { "s3_bucket": self.s3_bucket.name, @@ -60,22 +58,21 @@ def test_package_with_output_template_file_and_prefix(self, template_file): "s3_prefix": "regression/tests", } - self.regression_check(arguments) + self.regression_check(arguments, skip_sam_metadata) @parameterized.expand( [ - "aws-serverless-api.yaml", - "aws-appsync-graphqlschema.yaml", - "aws-appsync-resolver.yaml", - "aws-appsync-functionconfiguration.yaml", - "aws-apigateway-restapi.yaml", - "aws-apigatewayv2-httpapi.yaml", - "aws-elasticbeanstalk-applicationversion.yaml", - "aws-cloudformation-stack.yaml", - "aws-serverlessrepo-application.yaml", + ("aws-serverless-api.yaml", True), + ("aws-appsync-graphqlschema.yaml", True), + ("aws-appsync-resolver.yaml", True), + ("aws-appsync-functionconfiguration.yaml", True), + ("aws-apigateway-restapi.yaml", True), + ("aws-elasticbeanstalk-applicationversion.yaml", True), + ("aws-cloudformation-stack-regression.yaml", False), + ("aws-cloudformation-stack-regression.yaml", False), ] ) - def test_package_with_output_template_file_json_and_prefix(self, template_file): + def test_package_with_output_template_file_json_and_prefix(self, template_file, skip_sam_metadata=False): arguments = { "s3_bucket": self.s3_bucket.name, @@ -84,4 +81,4 @@ def test_package_with_output_template_file_json_and_prefix(self, template_file): "use_json": True, } - self.regression_check(arguments) + self.regression_check(arguments, skip_sam_metadata) diff --git a/tests/unit/lib/bootstrap/nested_stack/test_nested_stack_builder.py b/tests/unit/lib/bootstrap/nested_stack/test_nested_stack_builder.py index fa799a9db6..c9d09e783b 100644 --- a/tests/unit/lib/bootstrap/nested_stack/test_nested_stack_builder.py +++ b/tests/unit/lib/bootstrap/nested_stack/test_nested_stack_builder.py @@ -19,7 +19,7 @@ def test_with_function_added(self): function_logical_id = "FunctionLogicalId" layer_contents_folder = "layer/contents/folder" - function = generate_function(name=function_logical_id, runtime=function_runtime) + function = generate_function(function_id=function_logical_id, runtime=function_runtime) self.nested_stack_builder.add_function(stack_name, layer_contents_folder, function) self.assertTrue(self.nested_stack_builder.is_any_function_added())