문제

Given i have this example template:

{
    "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" : {
               ...
            }
        }
    }
}

Is it possible to specify multiple DependsOn in any way? Would be great to have somethink like:

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

Whats the normal way?

도움이 되었습니까?

해결책

Yes,

The DependsOn attribute can take a single string or list of strings.

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

Syntax:

"DependsOn" : [ String, ... ]

다른 팁

This answer comes up first in Google, so I will include how to do multiple dependson attributes in YAML, which I found in this answer.

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

Yes, "DependsOn" can take multiple strings. I have listed an example below:

"DependsOn": [ "S3BucketAppElbLogs", "ElbLogAppBucketPolicy" ]

{
    "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"
                }
            }
        }
    }      
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top