3

AWS에서 스핀 업되는 환경 유형을 제어하기 위해 플랫폼 조건을 사용하고 있습니다. 공유 리소스가 많이 있지만, 번호 조건에 따라 미리 구운 AMI가있는 특정 EC2 인스턴스가 필요합니다.클라우드 형성 리소스 생성의 여러 조건

"Parameters": { 
"Platform": { 
    "Description": "Select platform type - linux or windows", 
    "Default": "linux", 
    "Type": "String", 
    "AllowedValues": [ "linux", "windows", "both" ], 
    "ConstraintDescription": "Must enter either linux, windows, or both" 
}, 

그런 다음 conditions을 설정합니다. 나는 모든 EC2 리소스를 배포하는 Windows 또는 리눅스 EC2 생성을 트리거하기 위해 리눅스 또는 창을 사용, 또는 둘 모두를 사용하고 싶습니다 자원에서

"Conditions" : { 
    "LinuxPlatform" : {"Fn::Equals" : [{"Ref" : "Platform"}, "linux"]}, 
    "WindowsPlatform" : {"Fn::Equals" : [{"Ref" : "Platform"}, "windows"]}, 
    "BothPlatform" : {"Fn::Equals" : [{"Ref" : "Platform"}, "both"]} 
}, 

선언했다.

몇 가지 방법으로 fn:or을 사용하여 다음을 시도했습니다.

"Fn::Or": [{"Condition": "LinuxPlatform"}, {"Condition": "BothPlatform" }],

및 ...

"Condition" : { 
    "Fn::Or" : [ 
     {"Condition" : "LinuxPlatform"}, 
     {"Condition" : "BothPlatform"} 
    ] 
} 

배포와 AWS CLI 사용의 유효성을 검사 할 때 나는 다음과 같은 오류가 계속.

aws cloudformation validate-template --template-body  file://./cloudformation/deploy.json 

A client error (ValidationError) occurred when calling the ValidateTemplate operation: Template format error: Every Condition member must be a string. 

리소스 생성을 제어하기 위해 여러 조건을 평가할 수 있습니까? 그렇지 않으면 내가 시도 할 수있는 대안이 있습니까?

답변

4

에 한번 그런 당신의 Conditions의 바닥에

"MyCondition": {"Fn::Or": [{"Condition": "LinuxPlatform"}, {"Condition": "BothPlatform" }]} 

를 추가 :

"Conditions" : { 
     "LinuxPlatform" : {"Fn::Equals" : [{"Ref" : "Platform"}, "linux"]}, 
     "WindowsPlatform" : {"Fn::Equals" : [{"Ref" : "Platform"}, "windows"]}, 
     "BothPlatform" : {"Fn::Equals" : [{"Ref" : "Platform"}, "both"]}, 
     "MyCondition": {"Fn::Or": [{"Condition": "LinuxPlatform"}, {"Condition": "BothPlatform" }]} 
    }, 
+0

감사합니다, 나는 그 곧하려고합니다. 스택 작성 중에 드롭 다운에서 창을 선택하면 템플리트에서 EC2 자원의 50 %가 작성됩니다. 리눅스를 선택하면 다른 50 %입니다. 모든 인스턴스를 배포 및 테스트 목적으로 배포 할 수 있도록 둘 다 선택할 수 있어야합니다. 위의 방법을 사용하면 그렇게 할 수 있습니까, 아니면 창을 fn ::에 추가해야합니까? –

관련 문제