Skip to content
Merged
2 changes: 1 addition & 1 deletion samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def _construct_alias(self, name, function, version):
"""

if not name:
raise ValueError("Alias name is required to create an alias")
raise InvalidResourceException(self.logical_id, "Alias name is required to create an alias")

logical_id = "{id}Alias{suffix}".format(id=function.logical_id, suffix=name)
alias = LambdaAlias(logical_id=logical_id, attributes=self.get_passthrough_resource_attributes())
Expand Down
115 changes: 115 additions & 0 deletions tests/translator/input/error_function_invalid_autopublishalias.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
Parameters:
MyAlias:
Type: String
Default: ""
Resources:
InvalidAutoPublishAliasFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.lambda_handler
CodeUri: s3://bucket/object
Runtime: python3.7
AutoPublishAlias:
Ref: MyAlias
Events:
Get:
Type: Api
Properties:
Path: "/path"
Method: GET
# ---
# Parameters:
# Branch:
# Type: String
# Default: "DeploymentBucket"
# Globals:
# Function:
# AutoPublishAlias:
# Ref: Branch
# Description: __HIDDEN__
# Resources:
# # AdminAPICustomDomainRoute53:
# # Type: AWS::Route53::RecordSet
# # Properties:
# # HostedZoneName:
# # Ref: HostedZoneName
# # ResourceRecords:
# # - Fn::GetAtt:
# # - AdminAPICustomDomain
# # - DistributionDomainName
# # Type: CNAME
# # Name:
# # Fn::Sub: "${Branch}-${DomainName}"
# # TTL: 300
# TestFunction:
# Type: AWS::Serverless::Function
# Properties:
# CodeUri: s3://bucket/object
# Handler: lambda_test.lambda_handler
# Role:
# Fn::GetAtt:
# - LambdaExecutionRole
# - Arn
# Events:
# GetEvent:
# Type: Api
# Properties:
# Path: "/dar/test"
# Method: GET
# Runtime: python3.7
# AdminAPICustomDomain:
# Type: AWS::ApiGateway::DomainName
# Properties:
# CertificateArn:
# Ref: DomainCertificateArn
# DomainName:
# Fn::Sub: "${Branch}-${DomainName}"
# AdminAPICustomDomainBasePath:
# Type: AWS::ApiGateway::BasePathMapping
# Properties:
# DomainName:
# Ref: AdminAPICustomDomain
# RestApiId:
# Ref: AdminApi
# Stage:
# Ref: Branch
# ControlFileFunction:
# Type: AWS::Serverless::Function
# Properties:
# Handler: mdlcontrolfile.lambda_handler
# Role:
# Fn::GetAtt:
# - LambdaExecutionRole
# - Arn
# Timeout: 60
# CodeUri: s3://bucket/object
# Runtime: python3.7
# Events:
# GetEvent:
# Type: Api
# Properties:
# Path: "/dar/controlFile/create"
# Method: GET
# LambdaExecutionRole:
# Type: AWS::IAM::Role
# Properties:
# Policies:
# - PolicyName: AllowS3AssumeRole
# PolicyDocument:
# Version: '2012-10-17'
# Statement:
# - Action: s3:*
# Resource:
# - arn:aws:s3:::darmdl-test1
# - arn:aws:s3:::darmdl-test1/*
# Effect: Allow
# - Action: sts:AssumeRole
# Resource: arn:aws:iam::176494265958:role/EMR_EC2_DefaultRole
# Effect: Allow
# AssumeRolePolicyDocument:
# Version: '2012-10-17'
# Statement:
# - Action: sts:AssumeRole
# Effect: Allow
# Principal:
# Service: lambda.amazonaws.com
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"errors": [
{
"errorMessage": "Resource with id [InvalidAutoPublishAliasFunction] is invalid. Alias name is required to create an alias"
}
],
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [InvalidAutoPublishAliasFunction] is invalid. Alias name is required to create an alias"
}
3 changes: 1 addition & 2 deletions tests/translator/test_function_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def test_alias_creation(self):


def test_alias_creation_error(self):
with self.assertRaises(ValueError):
with self.assertRaises(InvalidResourceException):
self.sam_func._construct_alias(None, self.lambda_func, self.lambda_version)

def test_get_resolved_alias_name_must_work(self):
Expand Down Expand Up @@ -515,7 +515,6 @@ def test_get_resolved_alias_name_must_error_if_intrinsics_are_not_resolved_with_
ex = raises_assert.exception
self.assertEqual(expected_exception_msg, ex.message)


def _make_lambda_function(self, logical_id):
func = LambdaFunction(logical_id)
func.Code = {
Expand Down
1 change: 1 addition & 0 deletions tests/translator/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ def _generate_new_deployment_hash(self, logical_id, dict_to_hash, rest_api_to_sw
'error_cors_credentials_true_without_explicit_origin',
'error_function_invalid_codeuri',
'error_function_invalid_api_event',
'error_function_invalid_autopublishalias',
'error_function_invalid_event_type',
'error_function_invalid_layer',
'error_function_no_codeuri',
Expand Down