英文:
Use input parameter within lambda schedule in Cloudformation
问题
我正在尝试根据环境来启用/禁用 Lambda 定时事件,但运气不太好。如果环境是 prod
,它应该启用计划,如果是 dev
,它应该禁用计划。然而,计划状态并不遵守条件。目前在 dev 环境中它是启用的,但模板没有禁用它。如果我手动将 Enabled
属性设置为 false
,计划状态确实会变为禁用。所以不确定我做错了什么(或者我尝试的是否可行)。非常感谢任何帮助!
Parameters:
env:
Type: String
Conditions:
isProd:
!Equals [!Ref env, prod]
Resources:
func:
Type: AWS::Serverless::Function
Properties:
Events:
ScheduledEvent:
Type: Schedule
Properties:
Schedule: rate(5 minutes)
Enabled: !If [isProd, true, false]
英文:
I'm trying to enable/disable lambda scheduled event based on environment, and not having much luck. If the env is prod
, it should enable the schedule, and if it's dev
it should disable it. However, the schedule status doesn't obey the condition. It's currently enabled in dev, but the template doesn't disable it. If I set the Enabled
property to false
manually, the schedule status does change to disable. So not sure where I'm going wrong (or if what I'm trying to do is possible). Any help is greatly appreciated!
Parameters:
env:
Type: String
Conditions:
isProd:
!Equals [!Ref env, prod]
Resources:
func:
Type: AWS::Serverless::Function
Properties:
Events:
ScheduledEvent:
Type: Schedule
Properties:
Schedule: rate(5 minutes)
Enabled: !If [isProd, true, false]
答案1
得分: 3
好的,以下是翻译好的内容:
好的,经过进一步搜索,看起来使用条件语句设置Enabled属性并不太好用。我采用的解决方法是在Schedule属性中使用条件语句。
ScheduledEvent:
Type: Schedule
Properties:
Schedule: !If [isProd, "rate(5 minutes)", "cron(00 00 01 01 ? 1970)"]
感谢以下帖子指导我正确的方向:
英文:
Okay, so after a bit more searching, it looks like setting the Enabled property with conditional statements doesn't work so nice. The workaround I've put in place is to use conditional statements in the Schedule property.
ScheduledEvent:
Type: Schedule
Properties:
Schedule: !If [isProd, "rate(5 minutes)", "cron(00 00 01 01 ? 1970)"]
Thanks to these posts for point me in the right direction:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论