For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/cloudformation-aws-low-rds-backup-retention-period.md.
A documentation index is available at /llms.txt.
RDS clusters and standalone instances must retain automated backups for at least 7 days to ensure recoverability and limit data loss from accidental deletion, corruption, or operational errors. In AWS CloudFormation, the BackupRetentionPeriod property on AWS::RDS::DBCluster (and on standalone AWS::RDS::DBInstance resources) must be defined and set to 7 or greater. This rule flags AWS::RDS::DBCluster resources that omit BackupRetentionPeriod or set it to a value less than 7. For AWS::RDS::DBInstance resources, the check is enforced only when no AWS::RDS::DBCluster resources are defined in the template because cluster-level backup retention may govern recovery for clustered deployments. Resources missing the property or with BackupRetentionPeriod less than 7 will be reported.
AWSTemplateFormatVersion:"2010-09-09"Description:Creates RDS ClusterParameters:PMDatabaseEngine:Type:StringDefault:"MySQL"Description:"Database engine, Aurora, MySQL or PostgreSQL"PMRDSSG:Description:"Select the Security Group to use for the ELB"Type:"AWS::EC2::SecurityGroup::Id"PMDatabaseEngineVer:Type:StringDescription:"Database engine ver"PMDatabaseUsername:NoEcho:'true'Type:StringDescription:"Database admin account name"PMDatabasePassword:NoEcho:'true'Type:StringDescription:"Database admin account password"PMDBClusterParameterGroupName:Description:"Db Parameter Groupname"Type:StringPMDatabaseInstanceClass:Type:StringDefault:"db.t2.micro"Description:"Database instance class"PMPrivateSubnets:Description:"Subnets to launch instances into"Type:"List<AWS::EC2::Subnet::Id>"PMServerEnv:Description:"Server Environment name."ConstraintDescription:"Choose an Environment from the drop down"Type:StringPMDBClusterIdentifier:Description:"Db Cluster Name."Type:StringResources:DatabaseCluster:Type:"AWS::RDS::DBCluster"Properties:VpcSecurityGroupIds:- Ref:"PMRDSSG"Engine:!Ref "PMDatabaseEngine"EngineVersion:!Ref "PMDatabaseEngineVer"MasterUsername:!Ref "PMDatabaseUsername"MasterUserPassword:!Ref "PMDatabasePassword"DBClusterParameterGroupName:!Ref "RDSDBClusterParameterGroup"StorageEncrypted:trueBackupRetentionPeriod:16PreferredBackupWindow:'12:00-13:00'PreferredMaintenanceWindow:'mon:13:00-mon:14:00'Database1:Type:"AWS::RDS::DBInstance"Properties:Engine:!Ref "PMDatabaseEngine"DBClusterIdentifier:!Ref "DatabaseCluster"DBInstanceClass:!Ref "PMDatabaseInstanceClass"DBSubnetGroupName:!Ref "DbSubnetGroup"DBInstanceIdentifier:!Sub "${PMDBClusterIdentifier}-db1"Database2:Type:"AWS::RDS::DBInstance"Properties:Engine:!Ref "PMDatabaseEngine"DBClusterIdentifier:!Ref "DatabaseCluster"DBInstanceClass:!Ref "PMDatabaseInstanceClass"DBSubnetGroupName:!Ref "DbSubnetGroup"DBInstanceIdentifier:!Sub "${PMDBClusterIdentifier}-db2"DbSubnetGroup:Type:"AWS::RDS::DBSubnetGroup"Properties:DBSubnetGroupDescription:!Sub "${PMServerEnv} RDS DB subnet group"SubnetIds:Ref:"PMPrivateSubnets"RDSDBClusterParameterGroup:Type:"AWS::RDS::DBClusterParameterGroup"Properties:Description:"CloudFormation Sample Aurora Cluster Parameter Group"Family:!Ref "PMDBClusterParameterGroupName"Parameters:time_zone:"UTC"collation_connection:"utf8_general_ci"character_set_database:"utf8"Outputs:RdsDbId:Description:"RDS Database Cluster ID"Value:!Ref "DatabaseCluster"RdsEndpointAdd:Description:"RDS Database Endpoint"Value:!GetAtt "DatabaseCluster.Endpoint.Address"RdsReadEndpointAdd:Description:"RDS Read Database Endpoint"Value:!GetAtt "DatabaseCluster.ReadEndpoint.Address"RdsEndpointPort:Description:"RDS Database Port"Value:!GetAtt "DatabaseCluster.Endpoint.Port"DbUser:Description:"RDS Database admin account user"Value:!Ref "PMDatabaseUsername"DbPassword:Description:"RDS Database admin account password"Value:!Ref "PMDatabasePassword"
AWSTemplateFormatVersion:2010-09-09Description:RDS Storage EncryptedParameters:SourceDBInstanceIdentifier:Type:StringDBInstanceType:Type:StringSourceRegion:Type:StringResources:MyKey:Type:"AWS::KMS::Key"Properties:KeyPolicy:Version:2012-10-17Id:key-default-1Statement:- Sid:Enable IAM User PermissionsEffect:AllowPrincipal:AWS:!Join- ""- - "arn:aws:iam::"- !Ref "AWS::AccountId"- ":root"Action:"kms:*"Resource:"*"MyDBSmall:Type:"AWS::RDS::DBInstance"Properties:DBInstanceClass:!Ref DBInstanceTypeSourceDBInstanceIdentifier:!Ref SourceDBInstanceIdentifierSourceRegion:!Ref SourceRegionKmsKeyId:!Ref MyKeyBackupRetentionPeriod:7Outputs:InstanceId:Description:InstanceId of the newly created RDS InstanceValue:!Ref MyDBSmall
AWSTemplateFormatVersion:"2010-09-09"Parameters:DBUser:NoEcho:trueDescription:The database admin account usernameType:StringMinLength:1MaxLength:16AllowedPattern:"[a-zA-Z][a-zA-Z0-9]*"ConstraintDescription:must begin with a letter and contain only alphanumeric characters.DBPassword:NoEcho:trueDescription:The database admin account passwordType:StringMinLength:1MaxLength:41AllowedPattern:"[a-zA-Z0-9]*"ConstraintDescription:must contain only alphanumeric characters.Resources:MyDB:Type:"AWS::RDS::DBInstance"Properties:AllocatedStorage:'5'DBInstanceClass:db.t2.smallEngine:MySQLEngineVersion:'5.5'MasterUsername:!Ref DBUserMasterUserPassword:!Ref DBPasswordDBParameterGroupName:!Ref MyRDSParamGroupBackupRetentionPeriod:10MyRDSParamGroup:Type:"AWS::RDS::DBParameterGroup"Properties:Family:MySQL5.5Description:CloudFormation Sample Database Parameter GroupParameters:autocommit:'1'general_log:'1'old_passwords:'0'
Non-Compliant Code Examples
AWSTemplateFormatVersion:"2010-09-09"Description:Creates RDS ClusterParameters:PMDatabaseEngine:Type:StringDefault:"MySQL"Description:"Database engine, Aurora, MySQL or PostgreSQL"PMRDSSG:Description:"Select the Security Group to use for the ELB"Type:"AWS::EC2::SecurityGroup::Id"PMDatabaseEngineVer:Type:StringDescription:"Database engine ver"PMDatabaseUsername:NoEcho:'true'Type:StringDescription:"Database admin account name"PMDatabasePassword:NoEcho:'true'Type:StringDescription:"Database admin account password"PMDBClusterParameterGroupName:Description:"Db Parameter Groupname"Type:StringPMDatabaseInstanceClass:Type:StringDefault:"db.t2.micro"Description:"Database instance class"PMPrivateSubnets:Description:"Subnets to launch instances into"Type:"List<AWS::EC2::Subnet::Id>"PMServerEnv:Description:"Server Environment name."ConstraintDescription:"Choose an Environment from the drop down"Type:StringPMDBClusterIdentifier:Description:"Db Cluster Name."Type:StringResources:DatabaseCluster:Type:"AWS::RDS::DBCluster"Properties:VpcSecurityGroupIds:- Ref:"PMRDSSG"Engine:!Ref "PMDatabaseEngine"EngineVersion:!Ref "PMDatabaseEngineVer"MasterUsername:!Ref "PMDatabaseUsername"MasterUserPassword:!Ref "PMDatabasePassword"DBClusterParameterGroupName:!Ref "RDSDBClusterParameterGroup"StorageEncrypted:trueBackupRetentionPeriod:3PreferredBackupWindow:'12:00-13:00'PreferredMaintenanceWindow:'mon:13:00-mon:14:00'Database1:Type:"AWS::RDS::DBInstance"Properties:Engine:!Ref "PMDatabaseEngine"DBClusterIdentifier:!Ref "DatabaseCluster"DBInstanceClass:!Ref "PMDatabaseInstanceClass"DBSubnetGroupName:!Ref "DbSubnetGroup"DBInstanceIdentifier:!Sub "${PMDBClusterIdentifier}-db1"Database2:Type:"AWS::RDS::DBInstance"Properties:Engine:!Ref "PMDatabaseEngine"DBClusterIdentifier:!Ref "DatabaseCluster"DBInstanceClass:!Ref "PMDatabaseInstanceClass"DBSubnetGroupName:!Ref "DbSubnetGroup"DBInstanceIdentifier:!Sub "${PMDBClusterIdentifier}-db2"DbSubnetGroup:Type:"AWS::RDS::DBSubnetGroup"Properties:DBSubnetGroupDescription:!Sub "${PMServerEnv} RDS DB subnet group"SubnetIds:Ref:"PMPrivateSubnets"RDSDBClusterParameterGroup:Type:"AWS::RDS::DBClusterParameterGroup"Properties:Description:"CloudFormation Sample Aurora Cluster Parameter Group"Family:!Ref "PMDBClusterParameterGroupName"Parameters:time_zone:"UTC"collation_connection:"utf8_general_ci"character_set_database:"utf8"Outputs:RdsDbId:Description:"RDS Database Cluster ID"Value:!Ref "DatabaseCluster"RdsEndpointAdd:Description:"RDS Database Endpoint"Value:!GetAtt "DatabaseCluster.Endpoint.Address"RdsReadEndpointAdd:Description:"RDS Read Database Endpoint"Value:!GetAtt "DatabaseCluster.ReadEndpoint.Address"RdsEndpointPort:Description:"RDS Database Port"Value:!GetAtt "DatabaseCluster.Endpoint.Port"DbUser:Description:"RDS Database admin account user"Value:!Ref "PMDatabaseUsername"DbPassword:Description:"RDS Database admin account password"Value:!Ref "PMDatabasePassword"
AWSTemplateFormatVersion:2010-09-09Description:RDS Storage EncryptedParameters:SourceDBInstanceIdentifier:Type:StringDBInstanceType:Type:StringSourceRegion:Type:StringResources:MyKey:Type:"AWS::KMS::Key"Properties:KeyPolicy:Version:2012-10-17Id:key-default-1Statement:- Sid:Enable IAM User PermissionsEffect:AllowPrincipal:AWS:!Join- ""- - "arn:aws:iam::"- !Ref "AWS::AccountId"- ":root"Action:"kms:*"Resource:"*"MyDBSmall:Type:"AWS::RDS::DBInstance"Properties:DBInstanceClass:!Ref DBInstanceTypeSourceDBInstanceIdentifier:!Ref SourceDBInstanceIdentifierSourceRegion:!Ref SourceRegionKmsKeyId:!Ref MyKeyBackupRetentionPeriod:6Outputs:InstanceId:Description:InstanceId of the newly created RDS InstanceValue:!Ref MyDBSmall
AWSTemplateFormatVersion:"2010-09-09"Parameters:DBUser:NoEcho:trueDescription:The database admin account usernameType:StringMinLength:1MaxLength:16AllowedPattern:"[a-zA-Z][a-zA-Z0-9]*"ConstraintDescription:must begin with a letter and contain only alphanumeric characters.DBPassword:NoEcho:trueDescription:The database admin account passwordType:StringMinLength:1MaxLength:41AllowedPattern:"[a-zA-Z0-9]*"ConstraintDescription:must contain only alphanumeric characters.Resources:MyDB:Type:"AWS::RDS::DBInstance"Properties:AllocatedStorage:'5'DBInstanceClass:db.t2.smallEngine:MySQLEngineVersion:'5.5'MasterUsername:!Ref DBUserMasterUserPassword:!Ref DBPasswordDBParameterGroupName:!Ref MyRDSParamGroupMyRDSParamGroup:Type:"AWS::RDS::DBParameterGroup"Properties:Family:MySQL5.5Description:CloudFormation Sample Database Parameter GroupParameters:autocommit:'1'general_log:'1'old_passwords:'0'
1
2
rulesets:- CloudFormation / AWS # Rules to enforce / AWS.
Request a personalized demo
Get Started with Datadog
Ask AI
AI-generated responses may be inaccurate. Verify important info.