gpt4 book ai didi

amazon-web-services - 有条件地在 AWS sam 模板文件中启用事件计划

转载 作者:行者123 更新时间:2023-12-03 07:17:55 25 4
gpt4 key购买 nike

这是我的(缩短的)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 conditionIf condition上类。我已尝试以下所有方法:

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]

在测试所有这四种情况之间,我删除了整个堆栈,而不是尝试更新它们,如 this post suggested. 中的评论所示。我还三次检查了传入的参数不是 qc1,并且还只是将 Enabled 标志设置为 False 以确保它实际上会禁用计划,它确实做到了。此时我很困惑,有谁知道我做错了什么或我可以尝试什么?

最佳答案

我也遇到了同样的问题。显然,Enabled 属性不能很好地与 !If!Equals 配合使用。我通过修改 Schedule 属性修复了这个问题:

 Events:
InvocationLevel:
Type: Schedule
Properties:
Schedule: !If [IsQcEnv, "rate(2 hours)", "cron(0 0 31 2 ? *)"]

如果 envType 不是 qc1,则将使用 cron 表达式。该表达式将在 2 月 31 日执行您的函数。这意味着它永远不会执行。

我在这些答案的帮助下找到了这个解决方案:

https://stackoverflow.com/a/65214717/517173

https://stackoverflow.com/a/13938155/517173

关于amazon-web-services - 有条件地在 AWS sam 模板文件中启用事件计划,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67113915/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com