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
6 changes: 3 additions & 3 deletions samcli/lib/bootstrap/nested_stack/nested_stack_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions samcli/lib/bootstrap/nested_stack/nested_stack_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/deploy/test_deploy_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/package/test_package_command_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ source "https://rubygems.org"

gem "ruby-statistics"

ruby '~> 2.5.0'
ruby '~> 2.7.5'
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source "https://rubygems.org"

ruby '~> 2.5.0'
ruby '~> 2.7.5'
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ source "https://rubygems.org"

gem "ruby-statistics"

ruby '~> 2.5.0'
ruby '~> 2.7.5'
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source "https://rubygems.org"

ruby '~> 2.5.0'
ruby '~> 2.7.5'
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -25,6 +25,6 @@ Resources:
Description: Hello World Ruby Layer
ContentUri: after/Ruby/layer/
CompatibleRuntimes:
- ruby2.5
- ruby2.7
Metadata:
BuildMethod: ruby2.5
BuildMethod: ruby2.7
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -25,6 +25,6 @@ Resources:
Description: Hello World Ruby Layer
ContentUri: before/Ruby/layer/
CompatibleRuntimes:
- ruby2.5
- ruby2.7
Metadata:
BuildMethod: ruby2.5
BuildMethod: ruby2.7
2 changes: 1 addition & 1 deletion tests/integration/validate/test_validate_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
15 changes: 14 additions & 1 deletion tests/regression/package/regression_package_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
63 changes: 30 additions & 33 deletions tests/regression/package/test_package_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,60 +22,57 @@ 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,
"template_file": self.test_data_path.joinpath(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,
Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down