amazon-web-servicesaws-cloudformationaws-aurora-serverless

Log Retention for Aurora Serverless in CloudFormation


I have a Aurora Cluster (Serverless - PostgreSQL) setup in CloudFormation and I want to configure the Log Retention to be around 7 days but I haven't been able to find where to set this setting.

This is my CloudFormation definition for the DBCluster:

AuroraDBCluster:
    Type: AWS::RDS::DBCluster
    DeletionPolicy: Delete
    UpdateReplacePolicy: Delete
    Properties:
      Engine: aurora-postgresql
      EngineMode: serverless
      EngineVersion: 10.7
      DatabaseName: test-db
      DeletionProtection: false
      ScalingConfiguration:
        AutoPause: True
        MaxCapacity: 8
        MinCapacity: 2
        SecondsUntilAutoPause: 300
      VpcSecurityGroupIds: 
        - !Ref AuroraClusterSecurityGroup
      Port: !Ref DBPort
      MasterUsername:
        !Join ['', ['{{resolve:secretsmanager:', !Ref AuroraMasterSecret, ':SecretString:username}}' ]]
      MasterUserPassword:
        !Join ['', ['{{resolve:secretsmanager:', !Ref AuroraMasterSecret, ':SecretString:password}}' ]]
      DBSubnetGroupName: !Ref DBSubnetGroup      
      BackupRetentionPeriod: 35
      DBClusterParameterGroupName: !Ref RDSDBClusterParameterGroup
      StorageEncrypted: true
      KmsKeyId: !Ref AuroraKMSCMK

I have created a different LogGroup like this:

  AuroraClusterLogGroup:
    Type: "AWS::Logs::LogGroup"
    Properties:
      RetentionInDays: 7
      LogGroupName: !Join ["", ["/aws/rds/cluster/", !Ref AuroraDBCluster, /postgresql]]

But when I deploy the stack, it says:

CREATE_FAILED  AWS::Logs::LogGroup  AuroraClusterLogGroup  /aws/rds/cluster/aurora-serverless-db-ufeihfhef74465/postgresql already exists

Because (I think) the AuroraDBCluster resource creates its own LogGroup with the same name.

I have reviewed the AWS::RDS::DBCluster documentation but I have not found any references for the Log Retention.

What can I do in this case?

Thanks!


Solution

  • If Aurora has already created its own log group, you can't change it from CloudFormation. The only way to do this would be use custom resource in your template.

    In the custom resource you could use put-retention-policy to modify the retention time of chosen log group.