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
5 changes: 5 additions & 0 deletions samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ def to_cloudformation(self, **kwargs):
code_sha256 = None
if self.AutoPublishCodeSha256:
code_sha256 = intrinsics_resolver.resolve_parameter_refs(self.AutoPublishCodeSha256)
if not isinstance(code_sha256, string_types):
raise InvalidResourceException(
self.logical_id,
"AutoPublishCodeSha256 must be a string",
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems we support intrinsic Fn::Ref but not Fn::Sub, as shown in the test added.
If I understand correctly, Fn::Sub also resolves to a string. My question is - do we also want to support support Fn::Sub?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do want to support Fn::Sub but would prefer to deal with that when we tackle intrinsics support more broadly.

)
lambda_version = self._construct_version(
lambda_function, intrinsics_resolver=intrinsics_resolver, code_sha256=code_sha256
)
Expand Down
1 change: 1 addition & 0 deletions samtranslator/translator/logical_id_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(self, prefix, data_obj=None, data_hash=None):

:param prefix: Prefix for the logicalId
:param data_obj: Data object to trigger new changes on. If set to None, this is ignored
:param data_hash: Pre-computed hash, must be a string
"""

data_str = ""
Expand Down
28 changes: 28 additions & 0 deletions tests/model/test_sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,34 @@ def test_with_version_description(self):
generateFunctionVersion = [x for x in cfnResources if isinstance(x, LambdaVersion)]
self.assertEqual(generateFunctionVersion[0].Description, test_description)

@patch("boto3.session.Session.region_name", "ap-southeast-1")
def test_with_autopublish_bad_hash(self):
function = SamFunction("foo")
test_description = "foobar"

function.Runtime = "foo"
function.Handler = "bar"
function.CodeUri = "s3://foobar/foo.zip"
function.AutoPublishAlias = "live"
function.AutoPublishCodeSha256 = {"Fn::Sub": "${parameter1}"}

with pytest.raises(InvalidResourceException):
function.to_cloudformation(**self.kwargs)

@patch("boto3.session.Session.region_name", "ap-southeast-1")
def test_with_autopublish_good_hash(self):
function = SamFunction("foo")
test_description = "foobar"

function.Runtime = "foo"
function.Handler = "bar"
function.CodeUri = "s3://foobar/foo.zip"
function.AutoPublishAlias = "live"
function.AutoPublishCodeSha256 = "08240bdc52933ca4f88d5f75fc88cd3228a48feffa9920c735602433b94767ad"

# confirm no exception thrown
function.to_cloudformation(**self.kwargs)


class TestOpenApi(TestCase):
kwargs = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Description: Dip Investigation
Parameters:
GitCommitInfo:
Type: String
Default: hashhash
GitDirtInfo:
Type: String
Default: dirtyyy
AWSTemplateFormatVersion: '2010-09-09'
Resources:
Function:
Type: AWS::Serverless::Function
Properties:
VersionDescription:
Fn::Sub: ${GitCommitInfo}-${GitDirtyInfo}
MemorySize: 128
Handler: loader
Role:
Ref: IamRole
CodeUri: s3://some-bucket/somekey
AutoPublishCodeSha256:
Fn::Sub: ${GitCommitInfo}-${GitDirtInfo}-1
Runtime: go1.x
AutoPublishAlias: Alias1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"errors": [
{
"errorMessage": "[Function] is invalid. AutoPublishCodeSha256 must be a string"
}
],
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. AutoPublishCodeSha256 must be a string"
}