这是我的(缩短的)template.yml 文件:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: CF template for foobar
Parameters:
EnvType:
Type: String
Description: The environment to deploy to.
AllowedValues:
- dev1
- qc1
- uat1
Default: dev1
VeryImportantFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/very_important/
Handler: app.very_important
Runtime: python3.8
{unrelated policies and environment variables}
Events:
VeryImportantSchedule:
Type: Schedule
Properties:
Schedule: 'rate(2 hours)'
Enabled: True
我要做的是仅在 EnvType 参数设置为 qc1 时启用该计划。问题是,我无法让Equals 条件或If 条件工作。我已经尝试了以下所有方法:
Enabled: !Equals [!Ref EnvType, qc1]
Enabled: !Equals [!Ref EnvType, "qc1"]
和
Conditions:
IsQcEnv: !Equals [!Ref EnvType, qc1]
{and}
IsQcEnv: !Equals [!Ref EnvType, "qc1"]
....
....
....
Events:
VeryImportantSchedule:
Type: Schedule
Properties:
Schedule: 'rate(2 hours)'
Enabled: !If [IsQcEnv, True, False]
在测试所有这四个案例之间,我删除了我的整个堆栈,而不是尝试更新它们,正如这篇文章中的评论所建议的那样。我还三次检查了传入的参数不是 qc1,并且还只是将 Enabled 标志设置为 False 以确保它实际上会禁用计划,它确实这样做了。在这一点上我很困惑,有没有人知道我做错了什么或者我可以尝试什么?