AWS:Cloud Formation:是不是可以使用多个“DependsOn”?

Posted

技术标签:

【中文标题】AWS:Cloud Formation:是不是可以使用多个“DependsOn”?【英文标题】:AWS: Cloud Formation: Is it possible to use multiple "DependsOn"?AWS:Cloud Formation:是否可以使用多个“DependsOn”? 【发布时间】:2014-03-26 00:16:17 【问题描述】:

鉴于我有这个示例模板:


    "AWSTemplateFormatVersion" : "2010-09-09",
    "Mappings" : 
        "RegionMap" : 
            "us-west-1" :  "AMI" : "ami-655a0a20" ,
            ...
        
    ,
    "Resources" : 
        "Ec2Instance" : 
            "Type" : "AWS::EC2::Instance",
            "Properties" : 
                ...
            ,
            "DependsOn" : "myDB"
        ,
        "myDB" : 
            "Type" : "AWS::RDS::DBInstance",
            "Properties" : 
               ...
            
        ,
        "myDB2" : 
            "Type" : "AWS::RDS::DBInstance",
            "Properties" : 
               ...
            
        
    

是否可以以任何方式指定多个 DependsOn? 有这样的想法会很棒:

"DependsOn" : ["myDB", "myDB2"]

正常的方式是什么?

【问题讨论】:

【参考方案1】:

这个答案首先出现在 Google 中,所以我将介绍如何在 YAML 中执行多个依赖属性,我在 this answer 中找到了这些属性。

AnotherProductionResource:
  Type: AWS::CloudFormation::Stack
   Condition: ISProduction
   DependsOn:
   - AResource
   - MyProductionResource
   Properties:
     [...]

【讨论】:

【参考方案2】:

    "Description": "Create a variable number of EC2 instance resources.",
    "Parameters": 
        "InstanceCount": 
            "Description": "Number of EC2 instances (must be between 1 and 5).",
            "Type": "Number",
            "Default": 1,
            "MinValue": 1,
            "MaxValue": 5,
            "ConstraintDescription": "Must be a number between 1 and 5."
        ,
        "ImageId": 
            "Description": "Image ID to launch EC2 instances.",
            "Type": "AWS::EC2::Image::Id",
            "Default": "ami-31c9924e"
        ,
        "InstanceType": 
            "Description": "Instance type to launch EC2 instances.",
            "Type": "String",
            "Default": "m3.medium",
            "AllowedValues": [
                "m3.medium",
                "m3.large",
                "m3.xlarge",
                "m3.2xlarge"
            ]
        
    ,
    "Conditions": 
        "Launch1" : "Fn::Equals" : ["Ref" : "InstanceCount", "1"],
        "Launch2" : "Fn::Equals" : ["Ref" : "InstanceCount", "2"]       
    ,
    "Resources": 
        "Instance2": 
            "Condition": "Launch2",
            "Type": "AWS::EC2::Instance",
            "Properties": 
                "ImageId": 
                    "Ref": "ImageId"
                ,
                "InstanceType": 
                    "Ref": "InstanceType"
                
            ,
            "DependsOn": "Instance1"
        ,
        "Instance1": 
            "Condition": "Launch1",
            "Type": "AWS::EC2::Instance",
            "Properties": 
                "ImageId": 
                    "Ref": "ImageId"
                ,
                "InstanceType": 
                    "Ref": "InstanceType"
                
            
        
          

【讨论】:

【参考方案3】:

是的, “DependsOn”可以采用多个字符串。我在下面列出了一个示例:

“DependsOn”:[“S3BucketAppElbLogs”,“ElbLogAppBucketPolicy”]

【讨论】:

【参考方案4】:

是的,

DependsOn 属性可以采用单个字符串或字符串列表

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-dependson.html

语法:

“取决于”:[字符串,...]

【讨论】:

这有效,在 yml 的情况下 >> DependsOn: ConfigA,ConfigB @Forhad 在 yaml 中为您提供单个 ConfigA,ConfigB 字符串而不是列表

以上是关于AWS:Cloud Formation:是不是可以使用多个“DependsOn”?的主要内容,如果未能解决你的问题,请参考以下文章

如何在 AWS Cloud Formation 中实施嵌套堆栈?

AWS Cloud Formation 陷入 Review_In_Progress

AWS Cloud Formation !Sub & !Ref AWS::Serverless::Function Policies 中的函数

如何在 AWS SAM Cloud-Formation 中使用 Route53 设置自定义域名

我能否在 SAM 模板中使用 AWS Cloud Formation 资源语法,反之亦然?

如何使用 Cloud Formation 模板自动扩展 DynamoDB?