Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added VersionDescription property on Serverless::Function #835

Merged
merged 3 commits into from
Mar 8, 2019
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
4 changes: 3 additions & 1 deletion samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class SamFunction(SamResourceMacro):
'Layers': PropertyType(False, list_of(one_of(is_str(), is_type(dict)))),

# Intrinsic functions in value of Alias property are not supported, yet
'AutoPublishAlias': PropertyType(False, one_of(is_str()))
'AutoPublishAlias': PropertyType(False, one_of(is_str())),
'VersionDescription': PropertyType(False, is_str())
}
event_resolver = ResourceTypeResolver(samtranslator.model.eventsources, samtranslator.model.eventsources.pull,
samtranslator.model.eventsources.push,
Expand Down Expand Up @@ -359,6 +360,7 @@ def _construct_version(self, function, intrinsics_resolver):

lambda_version = LambdaVersion(logical_id=logical_id, attributes=attributes)
lambda_version.FunctionName = function.get_runtime_attr('name')
lambda_version.Description = self.VersionDescription

return lambda_version

Expand Down
26 changes: 25 additions & 1 deletion tests/model/test_sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from samtranslator.intrinsics.resolver import IntrinsicsResolver
from samtranslator.model import InvalidResourceException
from samtranslator.model.lambda_ import LambdaFunction
from samtranslator.model.lambda_ import LambdaFunction, LambdaVersion
from samtranslator.model.sam_resources import SamFunction


Expand All @@ -22,6 +22,7 @@ def test_with_code_uri(self):
function = SamFunction("foo")
function.CodeUri = "s3://foobar/foo.zip"


cfnResources = function.to_cloudformation(**self.kwargs)
generatedFunctionList = [x for x in cfnResources if isinstance(x, LambdaFunction)]
self.assertEqual(generatedFunctionList.__len__(), 1)
Expand All @@ -30,6 +31,7 @@ def test_with_code_uri(self):
"S3Bucket": "foobar",
})


@patch('boto3.session.Session.region_name', 'ap-southeast-1')
def test_with_zip_file(self):
function = SamFunction("foo")
Expand All @@ -46,3 +48,25 @@ def test_with_no_code_uri_or_zipfile(self):
function = SamFunction("foo")
with pytest.raises(InvalidResourceException):
function.to_cloudformation(**self.kwargs)

class TestVersionDescription(TestCase):
kwargs = {
'intrinsics_resolver': IntrinsicsResolver({}),
'event_resources': [],
'managed_policy_map': {
"foo": "bar"
}
}

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

function.CodeUri = "s3://foobar/foo.zip"
function.VersionDescription = test_description
function.AutoPublishAlias = "live"

cfnResources = function.to_cloudformation(**self.kwargs)
generateFunctionVersion = [x for x in cfnResources if isinstance(x, LambdaVersion)]
self.assertEqual(generateFunctionVersion[0].Description, test_description)
1 change: 1 addition & 0 deletions tests/translator/input/function_with_alias.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Resources:
Handler: hello.handler
Runtime: python2.7
AutoPublishAlias: live
VersionDescription: sam-testing

1 change: 1 addition & 0 deletions tests/translator/output/aws-cn/function_with_alias.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"DeletionPolicy": "Retain",
"Type": "AWS::Lambda::Version",
"Properties": {
"Description": "sam-testing",
"FunctionName": {
"Ref": "MinimalFunction"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"DeletionPolicy": "Retain",
"Type": "AWS::Lambda::Version",
"Properties": {
"Description": "sam-testing",
"FunctionName": {
"Ref": "MinimalFunction"
}
Expand Down
1 change: 1 addition & 0 deletions tests/translator/output/function_with_alias.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"DeletionPolicy": "Retain",
"Type": "AWS::Lambda::Version",
"Properties": {
"Description": "sam-testing",
"FunctionName": {
"Ref": "MinimalFunction"
}
Expand Down
1 change: 1 addition & 0 deletions versions/2016-10-31.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ DeadLetterQueue | `map` <span>&#124;</span> [DeadLetterQueue Object](#deadletter
DeploymentPreference | [DeploymentPreference Object](#deploymentpreference-object) | Settings to enable Safe Lambda Deployments. Read the [usage guide](../docs/safe_lambda_deployments.rst) for detailed information.
Layers | list of `string` | List of LayerVersion ARNs that should be used by this function. The order specified here is the order that they will be imported when running the Lambda function.
AutoPublishAlias | `string` | Name of the Alias. Read [AutoPublishAlias Guide](../docs/safe_lambda_deployments.rst#instant-traffic-shifting-using-lambda-aliases) for how it works
VersionDescription | `string` | A string that specifies the Description field which will be added on the new lambda version
ReservedConcurrentExecutions | `integer` | The maximum of concurrent executions you want to reserve for the function. For more information see [AWS Documentation on managing concurrency](https://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html)

##### Return values
Expand Down