我试图编写一个 CloudFormation,以从现有 RDS 数据库的时间点快照配置新的 RDS 实例。
但是,我发现在 CloudFormation 模板中提供快照时无法指定数据库名称,因此它始终会将其恢复到原始数据库。
我有this aws 博客上有类似的文章,不过我正在寻找是否有任何开箱即用的解决方案。
编辑 1
来 self 的 Cloud Formation 的 RDS 片段
Resources:
MyDB:
Type: AWS::RDS::DBInstance
Properties:
DBName: Fn::If ["UseDbSnapshot", !Ref AWS:NoValue, !Ref MyDBName]
DBSecurityGroups:
- !Ref MyDbSecurityByEC2SecurityGroup
- !Ref MyDbSecurityByCIDRIPGroup
AllocatedStorage: 20
DBInstanceClass: db.m1.small
Engine: MySQL
MasterUsername: root
MasterUserPassword: password
DBSnapshotIdentifier: Fn::If ["UseDbSnapshot", !Ref DBSnapshotIdentifier, !Ref AWS::NoValue]
DeletionPolicy: Snapshot
我可以尝试什么来解决这个问题?
最佳答案
您必须记住,当您想要从快照还原时,一些 RDS 属性(例如 MasterUsername)是不可自定义的。 AWS 文档说:
If you specify the SourceDBInstanceIdentifier or DBSnapshotIdentifier property, don't specify this property. The value is inherited from the source DB instance or snapshot.
所以只需省略这些参数,如下所示:
Parameters:
DBSnapshotIdentifier:
Description: 'Optional identifier for the DB cluster snapshot from which you want to restore'
Type: String
Default: ''
Conditions:
HasDBSnapshotIdentifier: !Not [!Equals [!Ref DBSnapshotIdentifier, '']]
Resources:
DBInstance:
Type: AWS::RDS::DBInstance
Properties:
...
DBSnapshotIdentifier: !If [HasDBSnapshotIdentifier, !Ref DBSnapshotIdentifier, !Ref 'AWS::NoValue']
KmsKeyId: !If [HasDBSnapshotIdentifier, !Ref 'AWS::NoValue', !If [HasEncryption, !Ref KmsKey, !Ref 'AWS::NoValue']]
MasterUsername: !If [HasDBSnapshotIdentifier, !Ref 'AWS::NoValue', !Ref MasterUsername]
MasterUserPassword: !If [HasDBSnapshotIdentifier, !Ref 'AWS::NoValue', !Ref MasterPassword]
StorageEncrypted: !If [HasDBSnapshotIdentifier, !Ref 'AWS::NoValue', !If
...
关于amazon-web-services - 无法创建从时间点快照配置新实例的 CloudFormation RDS 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61660524/