DevBabai
DevBabai

Reputation: 83

AWS cfn resource creation failed for recordset

I wanted to deploy a static website using cloudformation but I am having issues creating the record set. The stack creation was successful until the hosted zone in resource section. I'm not sure why there is an issue creating the record set for a hosted zone.

Error: The following resource(s) failed to create: [RecordSet].

        ---
AWSTemplateFormatVersion:  '2010-09-09'
Description: 'Assuming that you already have a Hosted Zone registered with Amazon Route 53, this Cfn template is to create a static site'
# Metadata:
#   'AWS::CloudFormation::Interface':
#     ParameterGroups:
#       - Label:
#           default: 'HostedZone name'
#         Parameters:
#           - HostedZoneName
Parameters:
  HostedZoneName:
    Description: "The DNS name of an existing Amazon Route 53 hosted zone"
    Type: String
    AllowedPattern: "(?!-)[a-zA-Z0-9-.]{1,63}(?<!-)"
    Default: "thecloudcrew.net"


Resources:

  S3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      AccessControl: PublicRead
      BucketName: !Ref HostedZoneName
      WebsiteConfiguration:
        IndexDocument: index.html
        ErrorDocument: error.html
      LoggingConfiguration:
        DestinationBucketName: !Ref S3LoggingBucket
        LogFilePrefix: logs

  WWWS3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Sub
        -  www.${domain}
        - { domain: !Ref HostedZoneName}
      WebsiteConfiguration:
        RedirectAllRequestsTo:
          HostName: !Ref HostedZoneName

  S3LoggingBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Sub
        - ${domain}.logs
        - { domain: !Ref HostedZoneName}
      AccessControl: LogDeliveryWrite

  HostedZone:
    Type: "AWS::Route53::HostedZone"
    Properties:
      HostedZoneConfig:
        Comment: "My Hosted zone for thecloudcrew.net"
      HostedZoneTags:
        -
          Key: Name
          Value: thecloudcrew
      Name: !Ref HostedZoneName

  RecordSet: #FIXME
    Type: "AWS::Route53::RecordSet"
    Properties:
      AliasTarget:
        DNSName: s3-website.us-east-2.amazonaws.com
        HostedZoneId: Z2O1EMRO9K5GLX
      Comment: "RecordSet for static website"
      HostedZoneId: !Ref HostedZone  #TODO
      Name: !Ref HostedZone
      Type: A
      #Region: 'us-east-2'
      # SetIdentifier: String
      # TTL: String
      # Weight: Integer

Upvotes: 1

Views: 1017

Answers (1)

Laurent Jalbert Simard
Laurent Jalbert Simard

Reputation: 6349

You're missing the Type: A property, you have to replace HosteZoneName by HostedZoneId. Also, remove Region it has no use in Route53 which is global.

Upvotes: 1

Related Questions