无法创建CoudFormation RDS模板,无法从时间点快照中提供新的实例。

问题描述 投票:0回答:1

我试图编写一个CloudFormation,以便从现有RDS DB的时间点快照中提供一个新的RDS实例。

但是,我知道,当您在CloudFormation模板中提供快照时,您不能指定db-name,因此它将总是将其还原为原始DB。

我已经得到了 这个 aws博客上同样的文章,虽然我在寻找是否有任何开箱即用的解决方案。

编辑1

我的 "云阵 "中的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

我可以尝试解决这个问题吗?

amazon-web-services amazon-cloudformation amazon-rds aws-cloudformation-custom-resource
1个回答
0
投票

你必须记住,当你想从快照恢复时,几个RDS属性(如MasterUsername)是不可定制的。AWS文档中说。

如果你指定了SourceDBInstanceIdentifier或DBSnapshotIdentifier属性,不要指定这个属性。该值会从源DB实例或快照中继承。

https:/docs.aws.amazon.comAWSCloudFormationlatestUserGuideaws-properties-rds-database-instance.html。

所以就像这样省略这些参数。

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 
      ...
© www.soinside.com 2019 - 2024. All rights reserved.