【问题标题】:Dynamic AWS Sam Schedule Event Input param动态 AWS Sam 计划事件输入参数
【发布时间】:2019-02-14 13:19:58
【问题描述】:

我们正在通过 SAM 自动化 lambda 以在 Schedule Event 上运行。我们使用 YAML,但我们无法弄清楚如何使用 !Sub 使输入变为动态。

如果您阅读sam documentation,它会说Input 必须是JSON formatted string

以下代码适用于我们:

Events:
    Event1:
      Type: Schedule
      Properties:
        Schedule: rate(1 minute)
        Input: >-
          {
            "sqsUrl": "https://sqs.12344.url",
            "snsArn": "arn:val"
          }

但我们需要像这样将动态参数插入Input

Events:
    Event1:
      Type: Schedule
      Properties:
        Schedule: rate(1 minute)
        Input: >-
          {
            "sqsUrl": "https://sqs.${AWS::AccountId}.url",
            "snsArn": "arn:val"
          }

我们已尝试以多种方式执行此操作,使用 !Sub 但部署总是失败,说它需要是有效的 JSON。

让这个 JSON 字符串使用变量的正确方法是什么?

谢谢, 标记

【问题讨论】:

    标签: amazon-web-services aws-lambda amazon-cloudformation aws-sam-cli aws-sam


    【解决方案1】:

    因此,您应该使用!Sub 函数包装所有Input 值(在您的情况下这是json-string,当然它应该用一些quotes 包装)。

    然后,它看起来像:

    Input:
      Fn::Sub: '{"sqsUrl": "https://sqs.${AWS::AccountId}.url","snsArn": "arn:val"}'
    

    【讨论】:

      【解决方案2】:

      我用过类似的东西:

      !Sub |
          {
            "sqsUrl": "https://sqs.${AWS::AccountId}.url",
            "snsArn": "arn:val"
          }
      

      该 | (以及 >- 等等)定义yaml handles the line breaks in the string 的方式。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-08-15
        • 2021-07-10
        • 2018-08-28
        • 2019-01-22
        • 2020-01-06
        • 2016-03-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多