Cloudformation的条件语句(Glue的子网)

Cloudformation's condition statement (Glue's subnet)

我需要我的 Glue 作业根据它所在的环境使用特定的子网 运行。下面的行 SubnetId 抛出语法错误。我在 aws 的文档中读到 true/false 评估可以用 !Ref 解决,问题似乎与条件语法有关。

SubnetId: !If [!Ref UseProdCondition, !Ref PrivateSubnetAz2, !Ref PrivateSubnetAz3]

  GlueJDBCConnection:
    Type: AWS::Glue::Connection
    UseProdCondition: !Equals [!Ref "${AppEnv}", "production"]
    Properties:
      CatalogId: !Ref AWS::AccountId
      ConnectionInput:
        ConnectionType: "JDBC"
        ConnectionProperties:
          USERNAME: !Ref Username
          PASSWORD: !Ref Password
          JDBC_CONNECTION_URL: !Ref GlueJDBCStringTarget
          sslMode: 'REQUIRED'
        PhysicalConnectionRequirements:
          AvailabilityZone:
            Ref: AvailabilityZone2
          SecurityGroupIdList:
            - Fn::GetAtt: GlueJobSecurityGroup.GroupId
          SubnetId: !If [!Ref UseProdCondition, !Ref PrivateSubnetAz2, !Ref PrivateSubnetAz3] 
        Name: !Ref JDBCConnectionName

需要将条件定义为单独的资源,稍后在特定资源中引用。

谢谢@MisterSmith!

AWSTemplateFormatVersion: 2010-09-09
Description: AWS Glue Spark Job

Conditions:
  UseProdCondition: !Equals [!Ref AppEnv, "production"]


 GlueJDBCConnection:
   Type: AWS::Glue::Connection
   Properties:
     CatalogId: !Ref AWS::AccountId
     ConnectionInput:
       ConnectionType: "JDBC"
       ConnectionProperties:
         USERNAME: !Ref Username
         PASSWORD: !Ref Password
         JDBC_CONNECTION_URL: !Ref GlueJDBCStringTarget
         sslMode: 'REQUIRED'
       PhysicalConnectionRequirements:
         AvailabilityZone:
           Ref: AvailabilityZone2
         SecurityGroupIdList:
           - Fn::GetAtt: GlueJobSecurityGroup.GroupId
         #SubnetId: !Ref PrivateSubnetAz2
         SubnetId: !If [UseProdCondition, !Ref PrivateSubnetAz2, !Ref PrivateSubnetAz3]
       Name: !Ref RTMIJDBCConnectionName