【问题标题】:Use input parameter within lambda schedule in Cloudformation在 Cloudformation 的 lambda 计划中使用输入参数
【发布时间】:2022-02-09 17:12:59
【问题描述】:

我正在尝试根据环境启用/禁用 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]

【问题讨论】:

  • 您是否使用默认值将其设置为false?

标签: go aws-lambda amazon-cloudformation aws-event-bridge


【解决方案1】:

好的,经过一番搜索后,使用条件语句设置 Enabled 属性看起来不太好。我采用的解决方法是在 Schedule 属性中使用条件语句。

ScheduledEvent:
  Type: Schedule
  Properties:
    Schedule: !If [isProd, "rate(5 minutes)", "cron(00 00 01 01 ? 1970)"]

感谢这些帖子为我指明了正确的方向:

Conditionally enabling an event schedule in AWS sam template file

Dynamically change event properties on aws cloudformation templates

【讨论】:

    猜你喜欢
    • 2016-03-25
    • 2021-01-02
    • 2016-06-17
    • 2017-06-02
    • 1970-01-01
    • 1970-01-01
    • 2021-03-17
    • 2019-02-14
    • 2022-06-12
    相关资源
    最近更新 更多