如何使用 AWS 子資源型別的條件
- 我想創建一個帶有 2 個帶條件的備份規則的 AWS 備份計劃(例如,如果我將 create2backup 規則設定為“true”,它應該創建規則 1 和規則 2,如果條件為假,它應該忽略創建第二個規則,它應該創建規則 1。
條件 - 創建規則為真 --- 創建規則 1 和規則 2
條件 - 創建規則為假 --- 創建規則 1 并應忽略創建規則 2 并退出
無論你的條件是什么,它都應該創建規則 1,條件應該只適用于規則 2。
Try1 :
BackupPlan:
Type: AWS::Backup::BackupPlan
Properties:
BackupPlan:
BackupPlanName: backupplan
BackupPlanRule:
-
RuleName: !Ref RuleName
- <Some condition>
RuleName: !Ref RuleName2
Try2:
StorageBackupPlan:
Type: AWS::Backup::BackupPlan
# DependsOn: StorageBackupVault
Properties:
BackupPlan:
BackupPlanName: !Ref BackupPlanName
BackupPlanRule:
!If
- Createbackuprule2
-
RuleName: !Ref RuleName
-
RuleName: !Ref RuleName2
Error for try 2 - Properties validation failed for resource StorageBackupPlan with message: #/BackupPlan/BackupPlanRule: expected type: JSONArray, found: JSONObject
Try 3 : worked but not as I expected, if condition is true it creates rule 1 if the condition is false it creates rule 2 - got this from below answer
StorageBackupPlan:
Type: AWS::Backup::BackupPlan
# DependsOn: StorageBackupVault
Properties:
BackupPlan:
BackupPlanName: !Ref BackupPlanName
BackupPlanRule:
!If
- Createbackuprule2
-
- RuleName: !Ref RuleName1
-
- RuleName: !Ref RuleName2
uj5u.com熱心網友回復:
您應該能夠通過使用這樣的內在Fn:If條件函式來實作所需的結果:
Parameters:
CreateNewRole:
Type: String
AllowedValues:
- yes
- no
RuleName:
Type: String
RuleName2:
Type: String
Conditions:
CreateNewRoleCondition:
!Equals
- !Ref CreateNewRole
- yes
Resources:
MyBackupPlan:
Type: AWS::Backup::BackupPlan
Properties:
BackupPlan:
BackupPlanName: backupplan
BackupPlanRule:
!If
- CreateNewRoleCondition
-
- RuleName: !Ref RuleName
-
- RuleName: !Ref RuleName2
uj5u.com熱心網友回復:
條件是頂級部分,不能在屬性部分中使用。它用于決定是否創建資源。您可以擁有兩種不同的資源并根據條件創建其中一種。這當然會造成一些重復。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/338235.html
標籤:亚马逊网络服务 if 语句 条件语句 亚马逊云形成 aws 备份
