ReadEndpoint.Address не найден для DBCluster - PullRequest
3 голосов
/ 13 апреля 2020

Я добавляю маршрут 53 к своему DBCluster и продолжаю сталкиваться с ошибкой: Attribute: ReadEndpoint.Address was not found for resource: <DBCluster-name>

Весь стек создается с помощью облачной информации.

Кроме того, следует отметить, что это для Авроры без сервера в случае, если это имеет значение?

Вот мой код:

AWSTemplateFormatVersion: 2010-09-09
Description: RDS Aurora serverless template
Parameters:
  CustomFunctionArn:
    Default: arn:aws:lambda:us-west-2:123456789:function:vault-secrets-read-lambda-prod
    Description: The ARN of the lambda function to retrieve password from Vault
    Type: String
  DBName:
    AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
    Description: Name of the database
    Type: String
  DBMasterUsername:
    AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
    Description: The master user name for the DB instance
    Type: String
  DBScalingAutoPauseEnabled:
    AllowedValues:
      - 'true'
      - 'false'
    Default: 'true'
    Description: Pause all DB instances after some inactivity
    Type: String
  DBScalingMaxCapacity:
    AllowedValues:
      - 2
      - 4
      - 8
      - 16
      - 32
      - 64
      - 192
      - 384
    Default: 8
    Description: The maximum capacity for an Aurora DB cluster in serverless DB engine mode
    Type: Number
  DBScalingMinCapacity:
    AllowedValues:
      - 2
      - 4
      - 8
      - 16
      - 32
      - 64
      - 192
      - 384
    Default: 2
    Description: The minimum capacity for an Aurora DB cluster in serverless DB engine mode
    Type: Number
  DBScalingSecondsUntilAutoPause:
    Default: 300
    Description: Auto pause after consecutive seconds of inactivity
    MinValue: 300
    MaxValue: 86400
    Type: Number
  Env:
    AllowedValues:
      - prod
      - qa
      - dev
    Type: String
    Description: Environment
  VaultPath:
    Default: secret/dev/dbPassword
    Type: String
  SnapshotId:
    Description: snapshot ID to restore DB cluster from
    Type: String


Conditions:
  EnableAutoPause:
    !Equals [!Ref DBScalingAutoPauseEnabled, 'true']
  DoNotUseSnapshot: !Equals
    - !Ref SnapshotId
    - ''

Mappings:
  Configuration:
    prod:
      HostedZoneEnv: mydomain.com
      HostedZoneId: 'XXX'
      SecurityGroup: sg-123321
      SubnetGroups:
      - subnet-123
      - subnet-456
      - subnet-789
      VPCId: vpc-555
      Tags:
        - Key: Name
          Value: my-db
        - Key: environment
          Value: prod
        - Key: component
          Value: rds-aurora
        - Key: classification
          Value: internal
    qa:
      HostedZoneEnv: mydomain-qa.com
      HostedZoneId: 'XXX'
      SecurityGroup: sg-321123
      SubnetGroups:
      - subnet-098
      - subnet-765
      - subnet-432
      VPCId: vpc-345543
      Tags:
        - Key: Name
          Value: my-db
        - Key: environment
          Value: qa
        - Key: component
          Value: rds-aurora
        - Key: classification
          Value: internal
    dev:
      HostedZoneEnv: mydomain-dev.com
      HostedZoneId: 'XXX'
      SecurityGroup: sg-f3453f
      SubnetGroups:
      - subnet-dsf24327
      - subnet-82542gsda
      - subnet-casaf2344
      VPCId: vpc-23dfsf
      Tags:
        - Key: Name
          Value: my-db
        - Key: environment
          Value: dev
        - Key: component
          Value: rds-aurora
        - Key: classification
          Value: internal

Resources:
  AuroraSG:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Allows access to RDS
      GroupName: !Sub '${AWS::StackName}-aurora-rds-${Env}'
      SecurityGroupIngress:
      - IpProtocol: -1
        CidrIp: 0.0.0.0/0
        FromPort: 5432
        ToPort: 5432
      Tags: !FindInMap [Configuration, !Ref Env, Tags]
      VpcId: !FindInMap [Configuration, !Ref Env, VPCId]

  GetValuefromVault:
    Type: Custom::CustomResource
    Properties:
      ServiceToken: !Ref CustomFunctionArn
      VaultKeyPath: !Ref VaultPath

  DBCluster:
    Type: 'AWS::RDS::DBCluster'
    DeletionPolicy: Snapshot
    UpdateReplacePolicy: Snapshot
    Properties:
      BackupRetentionPeriod: 7
      DBClusterParameterGroupName: default.aurora-postgresql10
      DBSubnetGroupName: !Ref DBSubnetGroup
      DatabaseName: !Ref DBName
      DeletionProtection: false
      # EnableHttpEndpoint: true
      Engine: aurora-postgresql
      EngineMode: serverless
      EngineVersion: '10.7'
      KmsKeyId: !If [DoNotUseSnapshot, !Ref KMSkey, !Ref 'AWS::NoValue']
      MasterUserPassword: !If [DoNotUseSnapshot, !GetAtt 'GetValuefromVault.ValueFromVault', !Ref 'AWS::NoValue']
      MasterUsername: !If [DoNotUseSnapshot, !Ref DBMasterUsername, !Ref 'AWS::NoValue']
      Port: 5432
      ScalingConfiguration:
        AutoPause: !If [EnableAutoPause, true, false]
        MaxCapacity: !Ref DBScalingMaxCapacity
        MinCapacity: !Ref DBScalingMinCapacity
        SecondsUntilAutoPause: !Ref DBScalingSecondsUntilAutoPause
      SnapshotIdentifier: !If [DoNotUseSnapshot, !Ref 'AWS::NoValue', !Ref SnapshotId]
      StorageEncrypted: true
      Tags: !FindInMap [Configuration, !Ref Env, Tags]
      VpcSecurityGroupIds:
        - !GetAtt [AuroraSG, GroupId]
        - !FindInMap [Configuration, !Ref Env, SecurityGroup]

  DBSubnetGroup:
    Type: 'AWS::RDS::DBSubnetGroup'
    Properties:
      DBSubnetGroupDescription: !Sub '${AWS::StackName}-${Env}'
      SubnetIds: !FindInMap [Configuration, !Ref Env, SubnetGroups]
      Tags: !FindInMap [Configuration, !Ref Env, Tags]

  KmsAlias:
    Type: AWS::KMS::Alias
    Properties:
      AliasName: !Sub 'alias/${AWS::StackName}-${Env}-aurora-rds'
      TargetKeyId: !Ref KMSkey

  KMSkey:
    Type: AWS::KMS::Key
    Properties:
      KeyPolicy:
        Id: key-consolepolicy-3
        Version: 2012-10-17
        Statement:
          - Sid: Enable IAM User Permissions
            Effect: Allow
            Principal:
              AWS: !Sub arn:aws:iam::${AWS::AccountId}:root
            Action: 'kms:*'
            Resource: '*'

  RecordSet:
    Type: AWS::Route53::RecordSet
    DependsOn: DBCluster
    Properties:
      HostedZoneId: !FindInMap [Configuration, !Ref Env, HostedZoneId]
      Name: !Join ['', [!Ref DBName, -writer-db, ., !FindInMap [Configuration, !Ref Env, HostedZoneEnv], .]]
      ResourceRecords:
      - !GetAtt DBCluster.Endpoint.Address
      TTL: '60'
      Type: CNAME

  ReadRecordSet: 
    Type: 'AWS::Route53::RecordSet'
    DependsOn:
    - DBCluster
    Properties:
      HostedZoneId: !FindInMap [Configuration, !Ref Env, HostedZoneId]
      Name: !Join ['', [!Ref DBName, -reader-db, ., !FindInMap [Configuration, !Ref Env, HostedZoneEnv], .]] 
      ResourceRecords:
      - !GetAtt DBCluster.ReadEndpoint.Address
      TTL: '60'
      Type: CNAME

Outputs:
  AuroraHost:
    Value: !GetAtt [DBCluster, Endpoint.Address]
    Export:
      Name: !Join [":", [ !Ref "AWS::StackName", 'Host' ]]
  AuroraSG:
    Value: !GetAtt AuroraSG.GroupId
    Export:
      Name: !Join [":", [ !Ref "AWS::StackName", AuroraSG ]]
  KMS:
    Value: !GetAtt [KMSkey, Arn]
    Export:
      Name: !Join [":", [ !Ref "AWS::StackName", 'KMS' ]]
  DNSName:
    Description: 'The connection endpoint for the DB cluster.'
    Value: !GetAtt 'DBCluster.Endpoint.Address'
    Export:
      Name: !Sub '${AWS::StackName}-DNSName'
  ReadDNSName:
    Description: 'The reader endpoint for the DB cluster.'
    Value: !GetAtt 'DBCluster.ReadEndpoint.Address'
    Export:
      Name: !Sub '${AWS::StackName}-ReadDNSName'

Некоторые вещи, которые я пробовал:

  • Создать новый стек: FAIL
  • Создать новый стек без ReadRecordSet: FAIL
  • Создать новый стек без RecordSet (старое имя для набора записей для чтения): FAIL
  • Создать новый стек без RecordSet (новое имя для чтения набора записей): FAIL
  • Добавить DependsOn в ReadRecordSet (для первого RecordSet): FAIL
  • Включение конечной точки HTTP на кластере: FAIL
  • Обновление TTL до 60: FAIL Обновление TTL до 0: FAIL

Кажется, что RecordSet создается нормально (я проверил это, добавив DependsOn: - RecordSet в ReadRecordSet, чтобы разрешить RecordSet сначала создать), так что ReadRecordSet не работает и не может найти ReadEndpoint.Address

Не уверен, что мне здесь не хватает, я гуглюсь как сумасшедший и не вижу много о эта ошибка. Любая помощь приветствуется!

1 Ответ

2 голосов
/ 14 апреля 2020

Оказывается, что для Aurora Serverless не требуется ReadRecordSet, поэтому весь раздел применим только к подготовленной БД, поэтому ReadEndpoint действительно не существует. К сожалению, в документации AWS это явно не упоминается.

...