3 個答案
- 最新
- 最多得票
- 最多評論
0
Hi, AFAIK, the best of what you can do is use !If like in HACK VI of https://garbe.io/blog/2017/07/17/cloudformation-hacks/ I would not say that it is ideal in syntax ;-) but at least you can deal with a list of variable length...
Parameters:
Env1:
Type: String
Description: An item of possible environment variables
Default: ''
Env2:
Type: String
Description: An item of possible environment variables
Default: ''
Env3:
Type: String
Description: An item of possible environment variables
Default: ''
Conditions:
Env1Exist: !Not [ !Equals [!Ref Env1, '']]
Env2Exist: !Not [ !Equals [!Ref Env2, '']]
Env3Exist: !Not [ !Equals [!Ref Env3, '']]
TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
TaskRoleArn: !Ref TaskRole
ContainerDefinitions:
- Name: !Ref AWS::StackName
Image: !Ref ImageName
Environment:
'Fn::If':
- Env1Exist
-
- Name: !Select [0, !Split ["|", !Ref Env1]]
Value: !Select [1, !Split ["|", !Ref Env1]]
- 'Fn::If':
- Env2Exist
-
Name: !Select [0, !Split ["|", !Ref Env2]]
Value: !Select [1, !Split ["|", !Ref Env2]]
- !Ref "AWS::NoValue"
- 'Fn::If':
- Env3Exist
-
Name: !Select [0, !Split ["|", !Ref Env3]]
Value: !Select [1, !Split ["|", !Ref Env3]]
- !Ref "AWS::NoValue"
- !Ref "AWS::NoValue"
0
I "solved" this once by just including a "reserved" word for empty entries, like "none", and passed the full array in. Then tested whether the element was the reserved word or not. Not very elegant but got the job done. Also, I used a parameter type of CommaDelimitedList
.
相關內容
- 已提問 1 年前
- 已提問 8 個月前
- AWS 官方已更新 2 年前
- AWS 官方已更新 1 年前