gpt4 book ai didi

amazon-web-services - CloudFormation 条件 EMR 实例

转载 作者:行者123 更新时间:2023-12-03 07:39:19 24 4
gpt4 key购买 nike

我在 CF 模板中使用条件语句时遇到了一些麻烦,我想以最简洁的方式有条件地指定 EMR 集群实例组或队列。

此构建没有错误。它选择使用实例组(如果是产品)或实例队列(如果非产品)使用两个单独的条件:

Parameters:
EnvironmentName:
Type: String
Description: 'Example: ci, qa, stage, prod'

Conditions:
IsPreProd: !Or
[!Equals [!Ref EnvironmentName, ci], !Equals [!Ref EnvironmentName, qa]]
IsProd: !Or
[!Equals [!Ref EnvironmentName, stage], !Equals [!Ref EnvironmentName, prod]]

Resources:
EMRCluster:
Type: 'AWS::EMR::Cluster'
Properties:
Instances:
CoreInstanceGroup:
!If
- IsProd
- InstanceCount: 1
InstanceType: m5.8xlarge
Market: ON_DEMAND
Name: CoreInstance
- !Ref "AWS::NoValue"
CoreInstanceFleet:
!If
- IsPreProd
- InstanceTypeConfigs:
- InstanceType: m5.8xlarge
TargetOnDemandCapacity: 1
TargetSpotCapacity: 1
LaunchSpecifications:
SpotSpecification:
TimeoutAction: SWITCH_TO_ON_DEMAND
TimeoutDurationMinutes: 10
- !Ref "AWS::NoValue"


我只想使用一个条件,如下所示,除非构建失败,告诉我在“If”所在的行上“YAML 格式不正确”。如果我像上面那样实现它,我最终会得到四个单独的条件,因为我还必须添加主实例组或队列。是否可以将这一切作为一个条件来完成?

Parameters:
EnvironmentName:
Type: String
Description: 'Example: ci, qa, stage, prod'

Conditions:
IsProd: !Or
[!Equals [!Ref EnvironmentName, stage], !Equals [!Ref EnvironmentName, prod]]

Resources:
EMRCluster:
Type: 'AWS::EMR::Cluster'
Properties:
Instances:
- !If
- IsProd
- CoreInstanceGroup:
InstanceCount: 1
InstanceType: m5.8xlarge
Market: ON_DEMAND
Name: CoreInstance
- CoreInstanceFleet:
InstanceTypeConfigs:
- InstanceType: m5.8xlarge
TargetOnDemandCapacity: 1
TargetSpotCapacity: 1
LaunchSpecifications:
SpotSpecification:
BlockDurationMinutes: 60
TimeoutAction: SWITCH_TO_ON_DEMAND
TimeoutDurationMinutes: 10

最佳答案

实例不是列表!If 之前不需要 -:

Resources:
EMRCluster:
Type: 'AWS::EMR::Cluster'
Properties:
Instances:
!If
- IsProd
- CoreInstanceGroup:
InstanceCount: 1
InstanceType: m5.8xlarge
Market: ON_DEMAND
Name: CoreInstance
- CoreInstanceFleet:
InstanceTypeConfigs:
- InstanceType: m5.8xlarge
TargetOnDemandCapacity: 1
TargetSpotCapacity: 1
LaunchSpecifications:
SpotSpecification:
BlockDurationMinutes: 60
TimeoutAction: SWITCH_TO_ON_DEMAND
TimeoutDurationMinutes: 10

关于amazon-web-services - CloudFormation 条件 EMR 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73736287/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com