AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: Custom Domain Parameters: DomainName: Type: String Description: Domain name for api ZoneId: Type: String Description: Zone ID if exists. If not leave as none. Default: none CertArn: Type: String Description: Certificate ARN if exists. If not leave as none. Default: none Conditions: CreateZone: !Equals [!Ref ZoneId, 'none'] CreateCert: !Equals [!Ref CertArn, 'none'] Resources: GeneratedZone: # If a Zone ID is not passed in the parameteres, then a new zone is created for the domain Type: AWS::Route53::HostedZone Condition: CreateZone Properties: Name: !Ref DomainName GeneratedCert: # If a Certificate ARN is not passed in the parameters, then a new cert is created and will required validation during the deploy Type: AWS::CertificateManager::Certificate Condition: CreateCert Properties: DomainName: !Ref DomainName ValidationMethod: DNS HttpApiGateway: # Creates a HTTP API endpoint under the customm domain Type: AWS::Serverless::HttpApi Properties: Domain: DomainName: !Ref DomainName CertificateArn: !If [CreateCert, !Ref GeneratedCert, !Ref CertArn] Route53: HostedZoneId: !If [CreateZone, !Ref GeneratedZone, !Ref ZoneId] HttpApiFunction: # Integration Lambda function for the HTTP API Type: AWS::Serverless::Function Properties: InlineCode: exports.handler = async (event) => JSON.stringify(event) Handler: index.handler Runtime: nodejs12.x Timeout: 30 Events: FetchHttp: Type: HttpApi Properties: ApiId: !Ref HttpApiGateway Method: GET Path: /