Amazon CloudFormation是否提供了在Multi-AZ配置中将RDS实例部署到不同环境中的规定?<



我正在尝试使用CloudFormation模板在不同环境中创建Amazon RDS实例。在Prod中有一个Multi-AZ需求,但其他环境不需要Multi-AZ。这将调用CloudFormation中的一个条件函数。

根据RDS CloudFormation文档并使用CloudFormation中的if条件,以下内容应该在模板中工作:

Conditions:
IsProd: !Equals [ !Ref EnvironmentType, prod ]
...
Resources:
MyRDSInstance:
Properties:
...
AvailabilityZone:
!If [ IsProd, AWS::NoValue, af-south-1a ]
...
MultiAZ: !If [ IsProd, true, false ]

IsProd求值为:

  • false,AvailabilityZone: af-south-1aMultiAZ: false
  • true,去掉AvailabilityZone,去掉MultiAZ: true,满足文档要求:

如果MultiAZ参数设置为true,则无法设置AvailabilityZone参数

但是,当尝试部署prod RDS实例时,在创建堆栈时,我仍然在CloudFormation中得到以下错误,从而阻止了资源的创建:

请求特定可用区对Multi-AZ实例无效。(服务:AmazonRDS;状态码:400;错误代码:InvalidParameterCombination;请求ID: e6177fe4-4a4b-4db3-ba66-5f0e0f7218eb;代理:null)

我怀疑这是AWS的一个bug,因为最近在源代码中应用了一个更改,尽管它与CDK有关,而不是CloudFormation:

  • 问题:当MultiAZ为true时,可用分区参数从堆栈中静默移除
  • 修复提交于2021年5月25日:修复(rds):添加异常抛出时az被定义为多az db inst....我得到的错误抛出在这个确切的修复。

可能是CloudFormation现在没有提供AWS::NoValue伪参数吗?如果这是源代码中的错误,是否有任何方法可以绕过这个问题,所以我仍然可以在prod环境中实现多az ?

所以我试图在我的终端复制相同的内容,但在我的情况下,我能够成功地创建RDS资源。我附上我使用过的模板供您参考。

AWSTemplateFormatVersion: 2010-09-09
Description: >-
Description": "AWS CloudFormation Sample Template for creating an Amazon RDS DB instance: 
Sample template showing how to create a DB instance with Enhanced Monitoring enabled. 
**WARNING** This template creates an RDS DB instance. You will be billed for the AWS 
resources used if you create a stack from this template.
Parameters:
IsMultiAZ:
Type: String
Default: false
AllowedValues: [true,false]
Description: Please enter either "true" or "false"
DBInstanceID:
Default: mydbinstance
Description: My database instance
Type: String
MinLength: '1'
MaxLength: '63'
AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
ConstraintDescription: >-
Must begin with a letter and must not end with a hyphen or contain two
consecutive hyphens.
DBName:
Default: mydb
Description: My database
Type: String
MinLength: '1'
MaxLength: '64'
AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
ConstraintDescription: Must begin with a letter and contain only alphanumeric characters.
DBInstanceClass:
Default: db.m5.large
Description: DB instance class
Type: String
ConstraintDescription: Must select a valid DB instance type.
DBAllocatedStorage:
Default: '50'
Description: The size of the database (GiB)
Type: Number
MinValue: '20'
MaxValue: '65536'
ConstraintDescription: must be between 20 and 65536 GiB.
DBUsername:
NoEcho: 'true'
Description: Username for MySQL database access
Type: String
MinLength: '1'
MaxLength: '16'
AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
ConstraintDescription: must begin with a letter and contain only alphanumeric characters.
DBPassword:
NoEcho: 'true'
Description: Password MySQL database access
Type: String
MinLength: '8'
MaxLength: '41'
AllowedPattern: '[a-zA-Z0-9]*'
ConstraintDescription: must contain only alphanumeric characters.
Conditions:
CheckIsMultiZone:
!Equals [!Ref IsMultiAZ, true]
Resources:
MyDB:
Type: 'AWS::RDS::DBInstance'
Properties:
DBInstanceIdentifier: !Ref DBInstanceID
DBName: !Ref DBName
DBInstanceClass: !Ref DBInstanceClass
AllocatedStorage: !Ref DBAllocatedStorage
Engine: MySQL
EngineVersion: "8.0.16"
MasterUsername: !Ref DBUsername
MasterUserPassword: !Ref DBPassword
MultiAZ: !Ref IsMultiAZ
AvailabilityZone: !If [CheckIsMultiZone, !Ref AWS::NoValue, "us-east-1a"]

正如你所看到的,我使用了与你相同的概念。你可以测试这个模板在你的结束,看看这是否工作。我在模板中发现的一个问题是,您正在使用AWS::NoValue,而正确的格式是!Ref AWS::NoValue,如我的模板所示。我相信这就是你的问题所在。您可以在这里查看示例。

相关内容

最新更新