Skip to content

Instantly share code, notes, and snippets.

@michimani
Created February 21, 2020 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michimani/a6240ebf8b33595c1e890e3cec72f72e to your computer and use it in GitHub Desktop.
Save michimani/a6240ebf8b33595c1e890e3cec72f72e to your computer and use it in GitHub Desktop.
CloudFormation template for setting up custom domain name for an API in API Gateway.
AWSTemplateFormatVersion: "2010-09-09"
Description: "Setup API Gateway custom domain name"
Parameters:
AcmArn:
Type: String
CustomDomainName:
Type: String
ApiID:
Type: String
DomainHostZoneId:
Type: String
Resources:
ApiGatewayCustomDomainName:
Type: "AWS::ApiGateway::DomainName"
Properties:
CertificateArn: !Ref AcmArn
DomainName: !Ref CustomDomainName
BasePathMapping:
Type: "AWS::ApiGateway::BasePathMapping"
DependsOn: ApiGatewayCustomDomainName
Properties:
DomainName: !Ref CustomDomainName
RestApiId: !Ref ApiID
Stage: api
CustomDomainRecord:
Type: "AWS::Route53::RecordSet"
Properties:
Name: !Ref CustomDomainName
Type: A
HostedZoneId: !Ref DomainHostZoneId
AliasTarget:
DNSName: !GetAtt ApiGatewayCustomDomainName.DistributionDomainName
HostedZoneId: !GetAtt ApiGatewayCustomDomainName.DistributionHostedZoneId
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment