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
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ test:
@pytest --cov samtranslator --cov-report term-missing --cov-fail-under $(CODE_COVERAGE) tests

black:
rm -f tests/*.pyc samtranslator/*.pyc
black setup.py samtranslator/* tests/* bin/*

black-check:
rm -f tests/*.pyc samtranslator/*.pyc
black --check setup.py samtranslator/* tests/* bin/*

# Command to run everytime you make changes to verify everything works
Expand Down
4 changes: 2 additions & 2 deletions samtranslator/model/api/api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def _construct_api_domain(self, rest_api):
basepath_mapping = ApiGatewayBasePathMapping(
self.logical_id + "BasePathMapping", attributes=self.passthrough_resource_attributes
)
basepath_mapping.DomainName = self.domain.get("DomainName")
basepath_mapping.DomainName = ref(self.domain.get("ApiDomainName"))
basepath_mapping.RestApiId = ref(rest_api.logical_id)
basepath_mapping.Stage = ref(rest_api.logical_id + ".Stage")
basepath_resource_list.extend([basepath_mapping])
Expand All @@ -315,7 +315,7 @@ def _construct_api_domain(self, rest_api):
basepath_mapping = ApiGatewayBasePathMapping(
logical_id, attributes=self.passthrough_resource_attributes
)
basepath_mapping.DomainName = self.domain.get("DomainName")
basepath_mapping.DomainName = ref(self.domain.get("ApiDomainName"))
basepath_mapping.RestApiId = ref(rest_api.logical_id)
basepath_mapping.Stage = ref(rest_api.logical_id + ".Stage")
basepath_mapping.BasePath = path
Expand Down
17 changes: 12 additions & 5 deletions samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def to_cloudformation(self, **kwargs):
if self.EventInvokeConfig:
function_name = lambda_function.logical_id
event_invoke_resources, event_invoke_policies = self._construct_event_invoke_config(
function_name, alias_name, intrinsics_resolver, conditions
function_name, alias_name, lambda_alias, intrinsics_resolver, conditions
)
resources.extend(event_invoke_resources)

Expand All @@ -171,7 +171,7 @@ def to_cloudformation(self, **kwargs):

return resources

def _construct_event_invoke_config(self, function_name, lambda_alias, intrinsics_resolver, conditions):
def _construct_event_invoke_config(self, function_name, alias_name, lambda_alias, intrinsics_resolver, conditions):
"""
Create a `AWS::Lambda::EventInvokeConfig` based on the input dict `EventInvokeConfig`
"""
Expand All @@ -182,7 +182,14 @@ def _construct_event_invoke_config(self, function_name, lambda_alias, intrinsics
resolved_event_invoke_config = intrinsics_resolver.resolve_parameter_refs(self.EventInvokeConfig)

logical_id = "{id}EventInvokeConfig".format(id=function_name)
lambda_event_invoke_config = LambdaEventInvokeConfig(logical_id=logical_id, attributes=self.resource_attributes)
if lambda_alias:
lambda_event_invoke_config = LambdaEventInvokeConfig(
logical_id=logical_id, depends_on=[lambda_alias.logical_id], attributes=self.resource_attributes
)
else:
lambda_event_invoke_config = LambdaEventInvokeConfig(
logical_id=logical_id, attributes=self.resource_attributes
)

dest_config = {}
input_dest_config = resolved_event_invoke_config.get("DestinationConfig")
Expand All @@ -209,8 +216,8 @@ def _construct_event_invoke_config(self, function_name, lambda_alias, intrinsics
policy_document.append(policy)

lambda_event_invoke_config.FunctionName = ref(function_name)
if lambda_alias:
lambda_event_invoke_config.Qualifier = lambda_alias
if alias_name:
lambda_event_invoke_config.Qualifier = alias_name
else:
lambda_event_invoke_config.Qualifier = "$LATEST"
lambda_event_invoke_config.DestinationConfig = dest_config
Expand Down
36 changes: 22 additions & 14 deletions tests/translator/output/api_with_basic_custom_domain.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@
"Type": "AWS::ApiGateway::BasePathMapping",
"Properties": {
"BasePath": "fetch",
"DomainName": "api-example.com",
"DomainName": {
"Ref": "ApiGatewayDomainName23cdccdf9c"
},
"RestApiId": {
"Ref": "MyApi"
},
Expand All @@ -163,15 +165,6 @@
"MyFunctionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"ManagedPolicyArns": [
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
}
],
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
Expand All @@ -187,14 +180,25 @@
}
}
]
}
},
"ManagedPolicyArns": [
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
}
]
}
},
"MyApigetBasePathMapping": {
"Type": "AWS::ApiGateway::BasePathMapping",
"Properties": {
"BasePath": "get",
"DomainName": "api-example.com",
"DomainName": {
"Ref": "ApiGatewayDomainName23cdccdf9c"
},
"RestApiId": {
"Ref": "MyApi"
},
Expand Down Expand Up @@ -246,7 +250,9 @@
"MyAnotherApiBasePathMapping": {
"Type": "AWS::ApiGateway::BasePathMapping",
"Properties": {
"DomainName": "another-example.com",
"DomainName": {
"Ref": "ApiGatewayDomainNameeab65c1531"
},
"RestApiId": {
"Ref": "MyAnotherApi"
},
Expand Down Expand Up @@ -301,7 +307,9 @@
"ServerlessRestApiBasePathMapping": {
"Type": "AWS::ApiGateway::BasePathMapping",
"Properties": {
"DomainName": "another-example.com",
"DomainName": {
"Ref": "ApiGatewayDomainNameeab65c1531"
},
"RestApiId": {
"Ref": "ServerlessRestApi"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"Properties": {
"BasePath": "fetch",
"DomainName": {
"Fn::Sub": "example-ap-southeast-1.com"
"Ref": "ApiGatewayDomainNamec0ed6fae34"
},
"RestApiId": {
"Ref": "MyApi"
Expand All @@ -110,15 +110,6 @@
"MyFunctionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"ManagedPolicyArns": [
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
}
],
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
Expand All @@ -134,7 +125,16 @@
}
}
]
}
},
"ManagedPolicyArns": [
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
}
]
},
"Condition": "C1"
},
Expand All @@ -143,7 +143,7 @@
"Properties": {
"BasePath": "get",
"DomainName": {
"Fn::Sub": "example-ap-southeast-1.com"
"Ref": "ApiGatewayDomainNamec0ed6fae34"
},
"RestApiId": {
"Ref": "MyApi"
Expand Down
24 changes: 13 additions & 11 deletions tests/translator/output/api_with_custom_domain_route53.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@
"Type": "AWS::ApiGateway::BasePathMapping",
"Properties": {
"BasePath": "one",
"DomainName": "example.com",
"DomainName": {
"Ref": "ApiGatewayDomainName0caaf24ab1"
},
"RestApiId": {
"Ref": "MyApi"
},
Expand All @@ -136,15 +138,6 @@
"MyFunctionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"ManagedPolicyArns": [
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
}
],
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
Expand All @@ -160,7 +153,16 @@
}
}
]
}
},
"ManagedPolicyArns": [
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
}
]
}
},
"MyApi": {
Expand Down
36 changes: 22 additions & 14 deletions tests/translator/output/aws-cn/api_with_basic_custom_domain.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@
"Type": "AWS::ApiGateway::BasePathMapping",
"Properties": {
"BasePath": "fetch",
"DomainName": "api-example.com",
"DomainName": {
"Ref": "ApiGatewayDomainName23cdccdf9c"
},
"RestApiId": {
"Ref": "MyApi"
},
Expand All @@ -171,15 +173,6 @@
"MyFunctionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"ManagedPolicyArns": [
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
}
],
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
Expand All @@ -195,14 +188,25 @@
}
}
]
}
},
"ManagedPolicyArns": [
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
}
]
}
},
"MyApigetBasePathMapping": {
"Type": "AWS::ApiGateway::BasePathMapping",
"Properties": {
"BasePath": "get",
"DomainName": "api-example.com",
"DomainName": {
"Ref": "ApiGatewayDomainName23cdccdf9c"
},
"RestApiId": {
"Ref": "MyApi"
},
Expand Down Expand Up @@ -262,7 +266,9 @@
"MyAnotherApiBasePathMapping": {
"Type": "AWS::ApiGateway::BasePathMapping",
"Properties": {
"DomainName": "another-example.com",
"DomainName": {
"Ref": "ApiGatewayDomainNameeab65c1531"
},
"RestApiId": {
"Ref": "MyAnotherApi"
},
Expand Down Expand Up @@ -319,7 +325,9 @@
"ServerlessRestApiBasePathMapping": {
"Type": "AWS::ApiGateway::BasePathMapping",
"Properties": {
"DomainName": "another-example.com",
"DomainName": {
"Ref": "ApiGatewayDomainNameeab65c1531"
},
"RestApiId": {
"Ref": "ServerlessRestApi"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"Properties": {
"BasePath": "fetch",
"DomainName": {
"Fn::Sub": "example-cn-north-1.com"
"Ref": "ApiGatewayDomainNamec0cd2d9dfc"
},
"RestApiId": {
"Ref": "MyApi"
Expand Down Expand Up @@ -116,15 +116,6 @@
"MyFunctionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"ManagedPolicyArns": [
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
}
],
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
Expand All @@ -140,7 +131,16 @@
}
}
]
}
},
"ManagedPolicyArns": [
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
}
]
},
"Condition": "C1"
},
Expand All @@ -149,7 +149,7 @@
"Properties": {
"BasePath": "get",
"DomainName": {
"Fn::Sub": "example-cn-north-1.com"
"Ref": "ApiGatewayDomainNamec0cd2d9dfc"
},
"RestApiId": {
"Ref": "MyApi"
Expand Down
Loading