Created
August 11, 2019 16:39
-
-
Save haranjackson/ad5822d1fdffff75b36728acdb6c8d43 to your computer and use it in GitHub Desktop.
An AWS CloudFormation template for adding a custom domain to an API deployed with API Gateway
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: 2010-09-09 | |
Parameters: | |
ApiId: | |
Type: String | |
Description: The ID of the API for which to create the custom domain | |
ApiStage: | |
Type: String | |
Description: The API stage to associate with this custom domain | |
CustomDomainName: | |
Type: String | |
Description: The custom domain name to use for the API | |
HostedZone: | |
Type: String | |
Description: The Route 53 hosted zone corresponding to the custom domain | |
Resources: | |
DomainCertificate: | |
Type: AWS::CertificateManager::Certificate | |
Properties: | |
DomainName: !Ref CustomDomainName | |
ValidationMethod: DNS | |
DomainName: | |
Type: AWS::ApiGateway::DomainName | |
Properties: | |
RegionalCertificateArn: !Ref DomainCertificate | |
DomainName: !Ref CustomDomainName | |
EndpointConfiguration: | |
Types: | |
- REGIONAL | |
BasePathMapping: | |
Type: AWS::ApiGateway::BasePathMapping | |
Properties: | |
DomainName: !Ref DomainName | |
RestApiId: !Ref ApiId | |
Stage: !Ref ApiStage | |
RecordSet: | |
Type: AWS::Route53::RecordSet | |
Properties: | |
AliasTarget: | |
DNSName: !GetAtt DomainName.RegionalDomainName | |
HostedZoneId: !GetAtt DomainName.RegionalHostedZoneId | |
HostedZoneName: !Ref HostedZone | |
Name: !Sub "${CustomDomainName}." | |
Type: A |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment