gpt4 book ai didi

amazon-web-services - Cloudformation 的条件语句(Glue 的子网)

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

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

子网 ID:!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

关于amazon-web-services - Cloudformation 的条件语句(Glue 的子网),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68486884/

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