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: 1 addition & 1 deletion samtranslator/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.21.0"
__version__ = "1.22.0"
12 changes: 5 additions & 7 deletions samtranslator/model/api/http_api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,9 @@ def _construct_api_domain(self, http_api):
endpoint = "REGIONAL"
# to make sure that default is always REGIONAL
self.domain["EndpointConfiguration"] = "REGIONAL"
elif endpoint not in ["EDGE", "REGIONAL"]:
elif endpoint not in ["REGIONAL"]:
raise InvalidResourceException(
self.logical_id,
"EndpointConfiguration for Custom Domains must be one of {}.".format(["EDGE", "REGIONAL"]),
self.logical_id, "EndpointConfiguration for Custom Domains must be one of {}.".format(["REGIONAL"]),
)
domain_config["EndpointType"] = endpoint
domain_config["CertificateArn"] = self.domain.get("CertificateArn")
Expand Down Expand Up @@ -312,10 +311,9 @@ def _construct_alias_target(self, domain):
alias_target["HostedZoneId"] = fnGetAtt(self.domain.get("ApiDomainName"), "RegionalHostedZoneId")
alias_target["DNSName"] = fnGetAtt(self.domain.get("ApiDomainName"), "RegionalDomainName")
else:
if route53.get("DistributionDomainName") is None:
route53["DistributionDomainName"] = fnGetAtt(self.domain.get("ApiDomainName"), "DistributionDomainName")
alias_target["HostedZoneId"] = "Z2FDTNDATAQYW2"
alias_target["DNSName"] = route53.get("DistributionDomainName")
raise InvalidResourceException(
self.logical_id, "Only REGIONAL endpoint is supported on HTTP APIs.",
)
return alias_target

def _add_auth(self):
Expand Down
36 changes: 18 additions & 18 deletions tests/model/api/test_http_api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def test_no_domain_name(self):
http_api = HttpApiGenerator(**self.kwargs)._construct_http_api()
with pytest.raises(InvalidResourceException) as e:
HttpApiGenerator(**self.kwargs)._construct_api_domain(http_api)
self.assertEquals(
self.assertEqual(
e.value.message,
"Resource with id [HttpApiId] is invalid. "
+ "Custom Domains only works if both DomainName and CertificateArn are provided.",
Expand All @@ -131,7 +131,7 @@ def test_no_cert_arn(self):
http_api = HttpApiGenerator(**self.kwargs)._construct_http_api()
with pytest.raises(InvalidResourceException) as e:
HttpApiGenerator(**self.kwargs)._construct_api_domain(http_api)
self.assertEquals(
self.assertEqual(
e.value.message,
"Resource with id [HttpApiId] is invalid. "
+ "Custom Domains only works if both DomainName and CertificateArn are provided.",
Expand All @@ -145,7 +145,7 @@ def test_basic_domain_default_endpoint(self):
self.assertIsNotNone(basepath, None)
self.assertEqual(len(basepath), 1)
self.assertIsNone(route, None)
self.assertEquals(domain.DomainNameConfigurations[0].get("EndpointType"), "REGIONAL")
self.assertEqual(domain.DomainNameConfigurations[0].get("EndpointType"), "REGIONAL")

def test_basic_domain_regional_endpoint(self):
self.kwargs["domain"] = {
Expand All @@ -159,7 +159,7 @@ def test_basic_domain_regional_endpoint(self):
self.assertIsNotNone(basepath, None)
self.assertEqual(len(basepath), 1)
self.assertIsNone(route, None)
self.assertEquals(domain.DomainNameConfigurations[0].get("EndpointType"), "REGIONAL")
self.assertEqual(domain.DomainNameConfigurations[0].get("EndpointType"), "REGIONAL")

def test_basic_domain_edge_endpoint(self):
self.kwargs["domain"] = {
Expand All @@ -168,12 +168,12 @@ def test_basic_domain_edge_endpoint(self):
"EndpointConfiguration": "EDGE",
}
http_api = HttpApiGenerator(**self.kwargs)._construct_http_api()
domain, basepath, route = HttpApiGenerator(**self.kwargs)._construct_api_domain(http_api)
self.assertIsNotNone(domain, None)
self.assertIsNotNone(basepath, None)
self.assertEqual(len(basepath), 1)
self.assertIsNone(route, None)
self.assertEquals(domain.DomainNameConfigurations[0].get("EndpointType"), "EDGE")
with pytest.raises(InvalidResourceException) as e:
HttpApiGenerator(**self.kwargs)._construct_api_domain(http_api)
self.assertEqual(
e.value.message,
"Resource with id [HttpApiId] is invalid. EndpointConfiguration for Custom Domains must be one of ['REGIONAL'].",
)

def test_bad_endpoint(self):
self.kwargs["domain"] = {
Expand All @@ -184,10 +184,10 @@ def test_bad_endpoint(self):
http_api = HttpApiGenerator(**self.kwargs)._construct_http_api()
with pytest.raises(InvalidResourceException) as e:
HttpApiGenerator(**self.kwargs)._construct_api_domain(http_api)
self.assertEquals(
self.assertEqual(
e.value.message,
"Resource with id [HttpApiId] is invalid. "
+ "EndpointConfiguration for Custom Domains must be one of ['EDGE', 'REGIONAL'].",
+ "EndpointConfiguration for Custom Domains must be one of ['REGIONAL'].",
)

def test_basic_route53(self):
Expand All @@ -202,7 +202,7 @@ def test_basic_route53(self):
self.assertIsNotNone(basepath, None)
self.assertEqual(len(basepath), 1)
self.assertIsNotNone(route, None)
self.assertEquals(domain.DomainNameConfigurations[0].get("EndpointType"), "REGIONAL")
self.assertEqual(domain.DomainNameConfigurations[0].get("EndpointType"), "REGIONAL")

def test_basepaths(self):
self.kwargs["domain"] = {
Expand All @@ -217,7 +217,7 @@ def test_basepaths(self):
self.assertIsNotNone(basepath, None)
self.assertEqual(len(basepath), 3)
self.assertIsNotNone(route, None)
self.assertEquals(domain.DomainNameConfigurations[0].get("EndpointType"), "REGIONAL")
self.assertEqual(domain.DomainNameConfigurations[0].get("EndpointType"), "REGIONAL")

def test_invalid_basepaths(self):
self.kwargs["domain"] = {
Expand All @@ -229,7 +229,7 @@ def test_invalid_basepaths(self):
http_api = HttpApiGenerator(**self.kwargs)._construct_http_api()
with pytest.raises(InvalidResourceException) as e:
HttpApiGenerator(**self.kwargs)._construct_api_domain(http_api)
self.assertEquals(
self.assertEqual(
e.value.message, "Resource with id [HttpApiId] is invalid. " + "Invalid Basepath name provided."
)

Expand All @@ -246,6 +246,6 @@ def test_basepaths(self):
self.assertIsNotNone(basepath, None)
self.assertEqual(len(basepath), 3)
self.assertIsNotNone(route, None)
self.assertEquals(route.HostedZoneName, None)
self.assertEquals(route.HostedZoneId, "xyz")
self.assertEquals(len(route.RecordSets), 2)
self.assertEqual(route.HostedZoneName, None)
self.assertEqual(route.HostedZoneId, "xyz")
self.assertEqual(len(route.RecordSets), 2)
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Parameters:
MyDomainName:
Type: String
Default: sam-v2-regional-test.com
Default: sam-example.com

MyDomainCert:
Type: String
Default: arn:aws:acm:us-east-1:551213647843:certificate/6c911401-620d-4d41-b89e-366c238bb2f3
Default: arn:aws:acm:us-east-1:123455353535:certificate/6c911401-620d-4d41-b89e-366c238bb2f3

Globals:
HttpApi:
Expand All @@ -15,7 +15,7 @@ Globals:
EndpointConfiguration: REGIONAL
BasePath: ["/basic", "/begin-here"]
Route53:
HostedZoneName: sam-v2-regional-test.com.
HostedZoneName: sam-example.com.


Resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Globals:
Domain:
DomainName: !Ref DomainName
CertificateArn: !Ref ACMCertificateArn
EndpointConfiguration: EDGE
BasePath:
- /one
Route53:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ Resources:
Domain:
DomainName: !Ref DomainName
CertificateArn: !Ref ACMCertificateArn
EndpointConfiguration: EDGE
BasePath:
- /one
Route53:
Expand Down
80 changes: 40 additions & 40 deletions tests/translator/output/api_with_basic_custom_domain_http.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"Parameters": {
"MyDomainName": {
"Default": "sam-v2-regional-test.com",
"Default": "sam-example.com",
"Type": "String"
},
"MyDomainCert": {
"Default": "arn:aws:acm:us-east-1:551213647843:certificate/6c911401-620d-4d41-b89e-366c238bb2f3",
"Default": "arn:aws:acm:us-east-1:123455353535:certificate/6c911401-620d-4d41-b89e-366c238bb2f3",
"Type": "String"
}
},
Expand All @@ -17,14 +17,29 @@
"Ref": "MyApi"
},
"DomainName": {
"Ref": "ApiGatewayDomainNameV2ab8e63947d"
"Ref": "ApiGatewayDomainNameV22dbf35af54"
},
"ApiMappingKey": "basic",
"Stage": {
"Ref": "MyApiProdStage"
}
}
},
"ApiGatewayDomainNameV22dbf35af54": {
"Type": "AWS::ApiGatewayV2::DomainName",
"Properties": {
"DomainName": "sam-example.com",
"DomainNameConfigurations": [
{
"CertificateArn": "arn:aws:acm:us-east-1:123455353535:certificate/6c911401-620d-4d41-b89e-366c238bb2f3",
"EndpointType": "REGIONAL"
}
],
"Tags": {
"httpapi:createdBy": "SAM"
}
}
},
"MyApiProdStage": {
"Type": "AWS::ApiGatewayV2::Stage",
"Properties": {
Expand Down Expand Up @@ -88,40 +103,14 @@
"Ref": "MyApi"
},
"DomainName": {
"Ref": "ApiGatewayDomainNameV2ab8e63947d"
"Ref": "ApiGatewayDomainNameV22dbf35af54"
},
"ApiMappingKey": "begin-here",
"Stage": {
"Ref": "MyApiProdStage"
}
}
},
"RecordSetGroup9616db1511": {
"Type": "AWS::Route53::RecordSetGroup",
"Properties": {
"HostedZoneName": "sam-v2-regional-test.com.",
"RecordSets": [
{
"AliasTarget": {
"HostedZoneId": {
"Fn::GetAtt": [
"ApiGatewayDomainNameV2ab8e63947d",
"RegionalHostedZoneId"
]
},
"DNSName": {
"Fn::GetAtt": [
"ApiGatewayDomainNameV2ab8e63947d",
"RegionalDomainName"
]
}
},
"Type": "A",
"Name": "sam-v2-regional-test.com"
}
]
}
},
"HttpApiFunctionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
Expand Down Expand Up @@ -152,19 +141,30 @@
]
}
},
"ApiGatewayDomainNameV2ab8e63947d": {
"Type": "AWS::ApiGatewayV2::DomainName",
"RecordSetGroup1f4f569a7e": {
"Type": "AWS::Route53::RecordSetGroup",
"Properties": {
"DomainNameConfigurations": [
"HostedZoneName": "sam-example.com.",
"RecordSets": [
{
"CertificateArn": "arn:aws:acm:us-east-1:551213647843:certificate/6c911401-620d-4d41-b89e-366c238bb2f3",
"EndpointType": "REGIONAL"
"AliasTarget": {
"HostedZoneId": {
"Fn::GetAtt": [
"ApiGatewayDomainNameV22dbf35af54",
"RegionalHostedZoneId"
]
},
"DNSName": {
"Fn::GetAtt": [
"ApiGatewayDomainNameV22dbf35af54",
"RegionalDomainName"
]
}
},
"Type": "A",
"Name": "sam-example.com"
}
],
"DomainName": "sam-v2-regional-test.com",
"Tags": {
"httpapi:createdBy": "SAM"
}
]
}
},
"MyApi": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"DomainNameConfigurations": [
{
"CertificateArn": "cert-arn-in-us-east-1",
"EndpointType": "EDGE"
"EndpointType": "REGIONAL"
}
],
"Tags": {
Expand All @@ -82,11 +82,16 @@
"RecordSets": [
{
"AliasTarget": {
"HostedZoneId": "Z2FDTNDATAQYW2",
"HostedZoneId": {
"Fn::GetAtt": [
"ApiGatewayDomainNameV20caaf24ab1",
"RegionalHostedZoneId"
]
},
"DNSName": {
"Fn::GetAtt": [
"ApiGatewayDomainNameV20caaf24ab1",
"DistributionDomainName"
"RegionalDomainName"
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,16 @@
"RecordSets": [
{
"AliasTarget": {
"HostedZoneId": "Z2FDTNDATAQYW2",
"HostedZoneId": {
"Fn::GetAtt": [
"ApiGatewayDomainNameV20caaf24ab1",
"RegionalHostedZoneId"
]
},
"DNSName": {
"Fn::GetAtt": [
"ApiGatewayDomainNameV20caaf24ab1",
"DistributionDomainName"
"RegionalDomainName"
]
}
},
Expand All @@ -67,11 +72,16 @@
},
{
"AliasTarget": {
"HostedZoneId": "Z2FDTNDATAQYW2",
"HostedZoneId": {
"Fn::GetAtt": [
"ApiGatewayDomainNameV20caaf24ab1",
"RegionalHostedZoneId"
]
},
"DNSName": {
"Fn::GetAtt": [
"ApiGatewayDomainNameV20caaf24ab1",
"DistributionDomainName"
"RegionalDomainName"
]
}
},
Expand All @@ -88,7 +98,7 @@
"DomainNameConfigurations": [
{
"CertificateArn": "cert-arn-in-us-east-1",
"EndpointType": "EDGE"
"EndpointType": "REGIONAL"
}
],
"Tags": {
Expand Down
Loading