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
3 changes: 2 additions & 1 deletion examples/2016-10-31/custom_domains_with_route53/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Example SAM template for setting up Api Gateway resources for custom domains.
1. A domain name. You can purchase a domain name from a domain name provider.
1. A certificate ARN. Set up or import a valid certificate into AWS Certificate Manager. If the endpoint is EDGE, the certificate must be created in us-east-1.
1. A HostedZone in Route53 for the domain name.
1. A Cloudfront Distribution for the domain if the endpoint is set to EDGE.

## PostRequisites
After deploying the template, make sure you configure the DNS settings on the domain name provider's website. You will need to add Type A and Type AAAA DNS records that are point to ApiGateway's Hosted Zone Id. Read more [here](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-api-gateway.html)
Expand All @@ -19,3 +18,5 @@ $ sam deploy \
--stack-name my-new-stack \
--capabilities CAPABILITY_IAM
```

Curl to the endpoint "http://example.com/home/fetch" should hit the Api.
Copy link
Contributor

Choose a reason for hiding this comment

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

home is the base path and fetch is the api path, correct? That's what it looks like looking at the example template, just want to make sure I understand this.

Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ Resources:
CertificateArn: !Ref ACMCertificateArn
EndpointConfiguration: EDGE
BasePath:
- /fetch
- /home
Route53:
HostedZoneId: ZQ1UAL4EFZVME
IpV6: true
DistributionDomainName: !GetAtt Distribution.DomainName
## ====== Everything below here is optional, leave this out if you want to use the internal Api Gateway distribution =======
DistributionDomainName: !GetAtt Distribution.DomainName

Distribution:
Type: AWS::CloudFront::Distribution
Expand Down
4 changes: 1 addition & 3 deletions samtranslator/model/api/api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,7 @@ def _construct_alias_target(self, domain):
alias_target['DNSName'] = fnGetAtt(self.domain.get('ApiDomainName'), 'RegionalDomainName')
else:
if route53.get('DistributionDomainName') is None:
raise InvalidResourceException(self.logical_id,
"Custom Domains support for EDGE requires the name "
"of a Distribution resource")
route53['DistributionDomainName'] = fnGetAtt(self.domain.get('ApiDomainName'), 'DistributionDomainName')
alias_target['HostedZoneId'] = 'Z2FDTNDATAQYW2'
alias_target['DNSName'] = route53.get('DistributionDomainName')
return alias_target
Expand Down
1 change: 0 additions & 1 deletion samtranslator/model/apigateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def make_auto_deployable(self, stage, openapi_version=None, swagger=None, domain
if openapi_version:
hash_input.append(str(openapi_version))
if domain:
hash_input.append(self._X_HASH_DELIMITER)
hash_input.append(json.dumps(domain))

data = self._X_HASH_DELIMITER.join(hash_input)
Expand Down
31 changes: 2 additions & 29 deletions tests/translator/input/api_with_custom_domain_route53.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,7 @@ Resources:
CertificateArn: !Ref ACMCertificateArn
EndpointConfiguration: EDGE
BasePath:
- /fetch
- /one
Route53:
HostedZoneId: ZQ1UAL4EFZVME
IpV6: true
DistributionDomainName: !GetAtt Distribution.DomainName

Distribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Enabled: true
HttpVersion: http2
Origins:
- DomainName: !Ref DomainName
Id: !Ref DomainName
CustomOriginConfig:
HTTPPort: 80
HTTPSPort: 443
OriginProtocolPolicy: https-only
DefaultCacheBehavior:
AllowedMethods: [ HEAD, DELETE, POST, GET, OPTIONS, PUT, PATCH ]
ForwardedValues:
QueryString: false
SmoothStreaming: false
Compress: true
TargetOriginId: !Ref DomainName
ViewerProtocolPolicy: redirect-to-https
PriceClass: PriceClass_100
ViewerCertificate:
SslSupportMethod: sni-only
AcmCertificateArn: !Ref ACMCertificateArn
IpV6: true
66 changes: 33 additions & 33 deletions tests/translator/output/api_with_basic_custom_domain.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "MyAnotherApiDeploymente89573907a"
"Ref": "MyAnotherApiDeployment48a61be119"
},
"RestApiId": {
"Ref": "MyAnotherApi"
Expand Down Expand Up @@ -119,18 +119,6 @@
}
}
},
"MyAnotherApiBasePathMapping": {
"Type": "AWS::ApiGateway::BasePathMapping",
"Properties": {
"DomainName": "another-example.com",
"RestApiId": {
"Ref": "MyAnotherApi"
},
"Stage": {
"Ref": "MyAnotherApiProdStage"
}
}
},
"MyAnotherApi": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
Expand Down Expand Up @@ -159,13 +147,17 @@
}
}
},
"MyApiDeploymentddf2dae73e": {
"Type": "AWS::ApiGateway::Deployment",
"MyApifetchBasePathMapping": {
"Type": "AWS::ApiGateway::BasePathMapping",
"Properties": {
"BasePath": "fetch",
"DomainName": "api-example.com",
"RestApiId": {
"Ref": "MyApi"
},
"Description": "RestApi deployment id: ddf2dae73e4e91595e8de4be7a30a1d207f32aab"
"Stage": {
"Ref": "MyApiProdStage"
}
}
},
"MyFunctionRole": {
Expand Down Expand Up @@ -245,13 +237,16 @@
}
}
},
"MyAnotherApiDeploymente89573907a": {
"Type": "AWS::ApiGateway::Deployment",
"MyAnotherApiBasePathMapping": {
"Type": "AWS::ApiGateway::BasePathMapping",
"Properties": {
"DomainName": "another-example.com",
"RestApiId": {
"Ref": "MyAnotherApi"
},
"Description": "RestApi deployment id: e89573907aa0c18379ba3bcc497b31454e88a664"
"Stage": {
"Ref": "MyAnotherApiProdStage"
}
}
},
"ApiGatewayDomainNameeab65c1531": {
Expand All @@ -266,39 +261,35 @@
"DomainName": "another-example.com"
}
},
"MyApifetchBasePathMapping": {
"Type": "AWS::ApiGateway::BasePathMapping",
"ServerlessRestApiDeployment3c44da8ffd": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"BasePath": "fetch",
"DomainName": "api-example.com",
"RestApiId": {
"Ref": "MyApi"
"Ref": "ServerlessRestApi"
},
"Stage": {
"Ref": "MyApiProdStage"
}
"Description": "RestApi deployment id: 3c44da8ffdf3025dc792391a61590b92e8e2ff48",
"StageName": "Stage"
}
},
"ServerlessRestApiProdStage": {
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "ServerlessRestApiDeployment7db01b740c"
"Ref": "ServerlessRestApiDeployment3c44da8ffd"
},
"RestApiId": {
"Ref": "ServerlessRestApi"
},
"StageName": "Prod"
}
},
"ServerlessRestApiDeployment7db01b740c": {
"MyApiDeploymentbfb0243af9": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "ServerlessRestApi"
"Ref": "MyApi"
},
"Description": "RestApi deployment id: 7db01b740cb897c4fc4175031f25e8123cc57ca9",
"StageName": "Stage"
"Description": "RestApi deployment id: bfb0243af9bffaabaf3bbc9d980266c6d6eb8471"
}
},
"ServerlessRestApiBasePathMapping": {
Expand All @@ -317,14 +308,23 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "MyApiDeploymentddf2dae73e"
"Ref": "MyApiDeploymentbfb0243af9"
},
"RestApiId": {
"Ref": "MyApi"
},
"StageName": "Prod"
}
},
"MyAnotherApiDeployment48a61be119": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "MyAnotherApi"
},
"Description": "RestApi deployment id: 48a61be119a247807ea0ef8378e6aa16592f90fa"
}
},
"ServerlessRestApi": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,6 @@
},
"Condition": "C1"
},
"MyApiDeployment6e1ee39b06": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "MyApi"
},
"Description": "RestApi deployment id: 6e1ee39b068c65688d05f859c3952e41396ecede"
},
"Condition": "C1"
},
"ServerlessRestApiProdStage": {
"Type": "AWS::ApiGateway::Stage",
"Properties": {
Expand Down Expand Up @@ -226,7 +216,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "MyApiDeployment6e1ee39b06"
"Ref": "MyApiDeployment462f07ab8f"
},
"RestApiId": {
"Ref": "MyApi"
Expand All @@ -235,6 +225,16 @@
},
"Condition": "C1"
},
"MyApiDeployment462f07ab8f": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "MyApi"
},
"Description": "RestApi deployment id: 462f07ab8fcdc437955985b08464280d2a9244be"
},
"Condition": "C1"
},
"ServerlessRestApi": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
Expand Down
Loading