代码之家  ›  专栏  ›  技术社区  ›  Shabbir Bata

如果AWS云信息不存在,如何通过AWS云信息创建AWS ECS集群

  •  1
  • Shabbir Bata  · 技术社区  · 6 年前

    我在my.json中指定以下代码块,通过AWS cloudformation创建集群。

    "MyCluster": {
          "Type" : "AWS::ECS::Cluster",
          "Properties" : {
          "ClusterName" : {
              "Ref": "EcsCluster"
            }
        }   
    }
    

    如果已经存在具有特定名称的集群,我想提供一个异常条件来忽略集群创建。

    1 回复  |  直到 6 年前
        1
  •  3
  •   Stephen    6 年前

    只能有条件地基于 Conditions

    您可以使用自定义资源来咀嚼 名称

    如果需要完全消除资源,则需要添加参数以打开或关闭资源:

    AWSTemplateFormatVersion: "2010-09-09"
    
    Parameters:
        CreateCluster:
            Type: "String"
            Description: "Whether to create the ECS Cluster"
            AllowedValues: [ "true", "false" ]
            Default: "false"
    ...
    
    Conditions:
        CreateCluster: { "Fn::Equals": [ { Ref: "CreateCluster" }, "true" ] }
    
    ....
    
    Resources:
        MyCluster:
            Type: "AWS::ECS::Cluster"
            Properties:
                ClusterName: { Ref: "EcsCluster" }
           Condition: "CreateCluster"
    

    Transform 要重写模板,请检查集群是否存在,如果存在,请删除资源定义。