CloudFormation 中 Aurora Serverless 的日志保留

Log Retention for Aurora Serverless in CloudFormation

我在 CloudFormation 中设置了一个 Aurora 集群(无服务器 - PostgreSQL),我想将日志保留时间配置为 7 天左右,但我无法找到设置此设置的位置。

这是我对 DBCluster 的 CloudFormation 定义:

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

我创建了一个不同的日志组,如下所示:

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

但是当我部署堆栈时,它显示:

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

因为(我认为)AuroraDBCluster 资源创建了自己的同名日志组。

我查看了 AWS::RDS::DBCluster 文档,但没有找到任何关于日志保留的参考资料。

遇到这种情况我该怎么办?

谢谢!

如果 Aurora 已经创建了自己的日志组,您无法从 CloudFormation 更改它。唯一的方法是在模板中使用 custom resource

在自定义资源中,您可以使用 put-retention-policy 修改所选日志组的保留时间。