简体   繁体   English

CloudFormation 条件 EMR 实例

[英]CloudFormation conditional EMR instances

I struggle a bit with the use of conditionals in CF templates, and I would like to conditionally specify EMR cluster instances groups or fleets in the most concise way.我在 CF 模板中使用条件语句时遇到了一些困难,我想以最简洁的方式有条件地指定 EMR 集群实例组或队列。

This builds w/o error.这构建没有错误。 It chooses to use instance groups if prod, or instance fleets if non-prod using two separate conditionals:如果是 prod,它会选择使用实例组,如果不是 prod,它会选择使用实例队列,使用两个单独的条件:

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" 

  

I would like to use just a single conditional, like below, except the build fails telling me 'YAML not well-formed' on the line where the 'If' is.我只想使用一个条件,如下所示,除了构建失败告诉我“如果”所在的行上的“YAML 格式不正确”。 If I implement it like above, I would end up having four separate conditionals since I also have to add master instance groups or fleets as well.如果我像上面那样实现它,我最终会得到四个单独的条件,因为我还必须添加主实例组或队列。 Is is possible to do it like this all as one conditional?是否有可能将这一切作为一个条件?

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   

Instances is not a list . Instances不是一个列表 You don't need - before !If :你不需要- before !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  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM