无服务器步骤函数:在 lambda 的有效负载中传递多个字段时出错

serverless step functions: Getting error when passing more than one fields in the payload for lambda

错误:Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: The value for the field 'Date.$' must be a valid JSONPath at /States/Insert Data Dynamodb/Parameters' (Service: AWSStepFunctions; Status Code: 400; Error Code: InvalidDefinition;

下面是对应的serverless.yaml代码。

我尝试将两个参数包装到编码的 json 字符串中并将其作为单个有效负载字段传递,它导致了同样的错误,但是当有效负载中只有一个普通字段时,此代码部署成功

关于如何传递两个参数有什么建议吗?

service: service-name

frameworkVersion: '2'

provider:
  name: aws
  runtime: go1.x
  lambdaHashingVersion: 20201221
  stage: ${opt:stage, self:custom.defaultStage}
region: us-east-1
  tags: ${self:custom.tagsObject}
  logRetentionInDays: 1
  timeout: 10
  deploymentBucket: lambda-repository
  memorySize: 128
  tracing:
    lambda: true

plugins:
  - serverless-step-functions

configValidationMode: error

stepFunctions:
  stateMachines:
    sortData:
      name: datasorting-dev
      type: STANDARD
      role: ${self:custom.datasorting.${self:provider.stage}.iam}
      definition:
        Comment: "Data Sort"
        StartAt: Query Data
        States:
          Query Data:
            Type: Task
            Resource: arn:aws:states:::athena:startQueryExecution.sync
            Parameters:
              QueryString: >-
               select * from table.data 
              WorkGroup: primary
              ResultConfiguration:
                OutputLocation: s3://output/location
            Next: Insert Data Dynamodb
          Insert Data Dynamodb: 
            Type: Task
            Resource: arn:aws:states:::lambda:invoke
            Parameters: 
              FunctionName: arn:aws:lambda:us-east-1:${account-id}:function:name
              Payload: 
                OutputLocation.$: $.QueryExecution.ResultConfiguration.OutputLocation
                Date.$: ${self:custom.dates.year}${self:custom.dates.month}${self:custom.dates.day}
            End: true 

您的 Date.$ 属性 的值为 ${self:custom.dates.year}${self:custom.dates.month}${self:custom.dates.day}。让我们假设:

const dates = {
  "year": "2000",
  "month": "01",
  "day": "20"
}

结果将是 Date.$: "20000120",这不是有效的 JSON 路径。

JSON路径需要以$符号开始,每一层都除以.

你想实现这样的目标吗? $.2000.01.20?

如您所见,问题不在于传递 2 个参数,而在于错误的字符串 JSON 由 Date.$.

的字符串插值创建的路径

一些有用的链接:

https://github.com/json-path/JsonPath

https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-paths.html