如何将常量字符串与 jsonpath 连接

LP1*_*P13 23 jsonpath aws-step-functions

我有 AWS step machine,其中一个 step 用于使用 SNS 服务通知失败。我想从inputjson 中选择一些元数据到传出消息中。所以我试图将常量字符串与 jsonpath 连接起来,如下所示

"Notify Failure": {
      "Type": "Task",
      "Resource": "arn:aws:states:::sns:publish",
      "Parameters": {
        "Message.$": "A job submitted through Step Functions failed for document id $.document_id",
        "Subject":"Job failed",
        "TopicArn": "arn:aws:sns:us-west-2:xxxxxxx:xxxxxxxx"
      },
      "End": true
    }
Run Code Online (Sandbox Code Playgroud)

document_id输入 json 中的属性之一在哪里

但是,当我尝试保存状态机定义时,出现错误

您的 ASL 定义有问题,请检查并重试 'Message.$' 字段的值必须是有效的 JSONPath

小智 26

我能够使用以下方法解决类似问题:

"Message.$": "States.Format('A job submitted through Step Functions failed for document id {}', $.document_id)",
Run Code Online (Sandbox Code Playgroud)

在AWS 新闻博客文章中进行了描述。


A.K*_*han 1

正如消息所示,您需要提供有效的 JSONPath。

"Message.$": "$.document_id"

您不能使用任何字符串插值,因为它会使 JSONPath 格式无效。您需要在前面的状态下构造消息。

  • 即使在前面的状态下,如果我不能咒语,你会怎么做呢?仅仅为了连接而创建 lambda 太过分了 (3认同)