Aws lambda 无法在Lambda中分析AppSync中的数据
给定以下Lambda函数:Aws lambda 无法在Lambda中分析AppSync中的数据,aws-lambda,graphql,aws-appsync,Aws Lambda,Graphql,Aws Appsync,给定以下Lambda函数: const AWS = require('aws-sdk') const { GraphQLClient } = require('graphql-request') exports.handler = async (event) => { const endpoint = process.env.APPSYNC_URL const key = process.env.APPSYNC_API_KEY const graphQLClient = n
const AWS = require('aws-sdk')
const { GraphQLClient } = require('graphql-request')
exports.handler = async (event) => {
const endpoint = process.env.APPSYNC_URL
const key = process.env.APPSYNC_API_KEY
const graphQLClient = new GraphQLClient(endpoint, {
headers: {
'x-api-key': key,
},
})
const record = event.Records.map((record) => {
return AWS.DynamoDB.Converter.unmarshall(record.dynamodb.NewImage)
})[0]
console.log(record)
// triggered from a stream on table update and functions as expected with the following log of record:
// {
// ph: { raw: 1.5327472527472525, value: 3.5675802197802193 },
// temperature: { raw: 734, value: 21.693799999999996 },
// location: 'aiza-005',
// free_chlorine: { raw: 0.002686366689053088, value: -2.4983210208193416 },
// pressure: { raw: 971, value: -0.2099600000000006 },
// uuid: '56e5bb6fcba64d0292a8ffc847e137e2',
// coords: [ 42.230445, -83.728103 ],
// flow: { raw: 3.994627266621894, value: -0.02686366689053088 },
// timestamp: 1603726382563
// }
const mutation = `mutation PublishWaterQuality($input: CreateWaterQualityInput!) {
publishWaterQuality(input: $input) {
coords
flow
free_chlorine
location
ph
pressure
temperature
timestamp
uuid
}
}`
let {
coords,
flow,
free_chlorine,
location,
ph,
pressure,
temperature,
timestamp,
uuid,
} = record
const variables = {
input: {
coords: JSON.stringify(coords),
flow: JSON.stringify(flow),
free_chlorine: JSON.stringify(free_chlorine),
location,
ph: JSON.stringify(ph),
pressure: JSON.stringify(pressure),
temperature: JSON.stringify(temperature),
timestamp,
uuid,
},
}
return data
}
…和以下关联的架构:
input CreateWaterQualityInput {
coords: AWSJSON!
flow: AWSJSON!
free_chlorine: AWSJSON!
location: String!
ph: AWSJSON!
pressure: AWSJSON!
temperature: AWSJSON!
timestamp: AWSTimestamp!
uuid: String!
}
type WaterQuality {
coords: AWSJSON!
flow: AWSJSON!
free_chlorine: AWSJSON!
location: String!
ph: AWSJSON!
pressure: AWSJSON!
temperature: AWSJSON!
timestamp: AWSTimestamp!
uuid: String!
}
type Mutation {
publishWaterQuality(input: CreateWaterQualityInput!): WaterQuality
}
…以及连接到publishWaterQuality的以下本地解析器:
请求
"payload": $util.toJson($context.args)
响应
$util.toJson($context.result)
我收到以下错误:
{
"errorType": "Error",
"errorMessage": "Expected JSON object but got STRING instead.: {\"response\":{\"data\":{\"publishWaterQuality\":null},\"errors\":[{\"path\":[\"publishWaterQuality\"],\"data\":null,\"errorType\":\"MappingTemplate\",\"errorInfo\":null,\"locations\":[{\"line\":2,\"column\":5,\"sourceName\":null}],\"message\":\"Expected JSON object but got STRING instead.\"}],\"status\":200},\"request\":{\"query\":\"mutation PublishWaterQuality($input: CreateWaterQualityInput!) {\\n publishWaterQuality(input: $input) {\\n coords\\n flow\\n free_chlorine\\n location\\n ph\\n pressure\\n temperature\\n timestamp\\n uuid\\n }\\n }\",\"variables\":{\"input\":{\"coords\":\"[42.230445,-83.728103]\",\"flow\":\"{\\\"raw\\\":3.994627266621894,\\\"value\\\":-0.02686366689053088}\",\"free_chlorine\":\"{\\\"raw\\\":0.002686366689053088,\\\"value\\\":-2.4983210208193416}\",\"location\":\"aiza-005\",\"ph\":\"{\\\"raw\\\":1.5327472527472525,\\\"value\\\":3.5675802197802193}\",\"pressure\":\"{\\\"raw\\\":971,\\\"value\\\":-0.2099600000000006}\",\"temperature\":\"{\\\"raw\\\":734,\\\"value\\\":21.693799999999996}\",\"timestamp\":1603726382563,\"uuid\":\"56e5bb6fcba64d0292a8ffc847e137e2\"}}}}",
"response": {
"data": {
"publishWaterQuality": null
},
"errors": [
{
"path": [
"publishWaterQuality"
],
"data": null,
"errorType": "MappingTemplate",
"errorInfo": null,
"locations": [
{
"line": 2,
"column": 5,
"sourceName": null
}
],
"message": "Expected JSON object but got STRING instead."
}
],
"status": 200
},
"request": {
"query": "mutation PublishWaterQuality($input: CreateWaterQualityInput!) {\n publishWaterQuality(input: $input) {\n coords\n flow\n free_chlorine\n location\n ph\n pressure\n temperature\n timestamp\n uuid\n }\n }",
"variables": {
"input": {
"coords": "[42.230445,-83.728103]",
"flow": "{\"raw\":3.994627266621894,\"value\":-0.02686366689053088}",
"free_chlorine": "{\"raw\":0.002686366689053088,\"value\":-2.4983210208193416}",
"location": "aiza-005",
"ph": "{\"raw\":1.5327472527472525,\"value\":3.5675802197802193}",
"pressure": "{\"raw\":971,\"value\":-0.2099600000000006}",
"temperature": "{\"raw\":734,\"value\":21.693799999999996}",
"timestamp": 1603726382563,
"uuid": "56e5bb6fcba64d0292a8ffc847e137e2"
}
}
},
"stack": [
"Error: Expected JSON object but got STRING instead.: {\"response\":{\"data\":{\"publishWaterQuality\":null},\"errors\":[{\"path\":[\"publishWaterQuality\"],\"data\":null,\"errorType\":\"MappingTemplate\",\"errorInfo\":null,\"locations\":[{\"line\":2,\"column\":5,\"sourceName\":null}],\"message\":\"Expected JSON object but got STRING instead.\"}],\"status\":200},\"request\":{\"query\":\"mutation PublishWaterQuality($input: CreateWaterQualityInput!) {\\n publishWaterQuality(input: $input) {\\n coords\\n flow\\n free_chlorine\\n location\\n ph\\n pressure\\n temperature\\n timestamp\\n uuid\\n }\\n }\",\"variables\":{\"input\":{\"coords\":\"[42.230445,-83.728103]\",\"flow\":\"{\\\"raw\\\":3.994627266621894,\\\"value\\\":-0.02686366689053088}\",\"free_chlorine\":\"{\\\"raw\\\":0.002686366689053088,\\\"value\\\":-2.4983210208193416}\",\"location\":\"aiza-005\",\"ph\":\"{\\\"raw\\\":1.5327472527472525,\\\"value\\\":3.5675802197802193}\",\"pressure\":\"{\\\"raw\\\":971,\\\"value\\\":-0.2099600000000006}\",\"temperature\":\"{\\\"raw\\\":734,\\\"value\\\":21.693799999999996}\",\"timestamp\":1603726382563,\"uuid\":\"56e5bb6fcba64d0292a8ffc847e137e2\"}}}}",
" at GraphQLClient.<anonymous> (/var/task/node_modules/graphql-request/dist/index.js:172:35)",
" at step (/var/task/node_modules/graphql-request/dist/index.js:63:23)",
" at Object.next (/var/task/node_modules/graphql-request/dist/index.js:44:53)",
" at fulfilled (/var/task/node_modules/graphql-request/dist/index.js:35:58)",
" at processTicksAndRejections (internal/process/task_queues.js:97:5)"
]
}
{
"errorType": "Error",
"errorMessage": "Variable 'coords' has an invalid value. Unable to parse [42.230445, -83.728103] as valid JSON.: {\"response\":{\"data\":null,\"errors\":[{\"path\":null,\"locations\":[{\"line\":1,\"column\":30,\"sourceName\":null}],\"message\":\"Variable 'coords' has an invalid value. Unable to parse [42.230445, -83.728103] as valid JSON.\"}],\"status\":200},\"request\":{\"query\":\"mutation PublishWaterQuality($input: CreateWaterQualityInput!) {\\n publishWaterQuality(input: $input) {\\n coords\\n flow\\n free_chlorine\\n location\\n ph\\n pressure\\n temperature\\n timestamp\\n uuid\\n }\\n }\",\"variables\":{\"input\":{\"coords\":[42.230445,-83.728103],\"flow\":{\"raw\":4,\"value\":0},\"free_chlorine\":{\"raw\":0.002686366689053088,\"value\":-2.4983210208193416},\"location\":\"aiza-005\",\"ph\":{\"raw\":1.5327472527472525,\"value\":3.5675802197802193},\"pressure\":{\"raw\":973,\"value\":-0.1956800000000003},\"temperature\":{\"raw\":734,\"value\":21.693799999999996},\"timestamp\":1603726443629,\"uuid\":\"0bed82734bb148279187a6b7bac17555\"}}}}",
"response": {
"data": null,
"errors": [
{
"path": null,
"locations": [
{
"line": 1,
"column": 30,
"sourceName": null
}
],
"message": "Variable 'coords' has an invalid value. Unable to parse [42.230445, -83.728103] as valid JSON."
}
],
"status": 200
},
"request": {
"query": "mutation PublishWaterQuality($input: CreateWaterQualityInput!) {\n publishWaterQuality(input: $input) {\n coords\n flow\n free_chlorine\n location\n ph\n pressure\n temperature\n timestamp\n uuid\n }\n }",
"variables": {
"input": {
"coords": [
42.230445,
-83.728103
],
"flow": {
"raw": 4,
"value": 0
},
"free_chlorine": {
"raw": 0.002686366689053088,
"value": -2.4983210208193416
},
"location": "aiza-005",
"ph": {
"raw": 1.5327472527472525,
"value": 3.5675802197802193
},
"pressure": {
"raw": 973,
"value": -0.1956800000000003
},
"temperature": {
"raw": 734,
"value": 21.693799999999996
},
"timestamp": 1603726443629,
"uuid": "0bed82734bb148279187a6b7bac17555"
}
}
},
"stack": [
"Error: Variable 'coords' has an invalid value. Unable to parse [42.230445, -83.728103] as valid JSON.: {\"response\":{\"data\":null,\"errors\":[{\"path\":null,\"locations\":[{\"line\":1,\"column\":30,\"sourceName\":null}],\"message\":\"Variable 'coords' has an invalid value. Unable to parse [42.230445, -83.728103] as valid JSON.\"}],\"status\":200},\"request\":{\"query\":\"mutation PublishWaterQuality($input: CreateWaterQualityInput!) {\\n publishWaterQuality(input: $input) {\\n coords\\n flow\\n free_chlorine\\n location\\n ph\\n pressure\\n temperature\\n timestamp\\n uuid\\n }\\n }\",\"variables\":{\"input\":{\"coords\":[42.230445,-83.728103],\"flow\":{\"raw\":4,\"value\":0},\"free_chlorine\":{\"raw\":0.002686366689053088,\"value\":-2.4983210208193416},\"location\":\"aiza-005\",\"ph\":{\"raw\":1.5327472527472525,\"value\":3.5675802197802193},\"pressure\":{\"raw\":973,\"value\":-0.1956800000000003},\"temperature\":{\"raw\":734,\"value\":21.693799999999996},\"timestamp\":1603726443629,\"uuid\":\"0bed82734bb148279187a6b7bac17555\"}}}}",
" at GraphQLClient.<anonymous> (/var/task/node_modules/graphql-request/dist/index.js:172:35)",
" at step (/var/task/node_modules/graphql-request/dist/index.js:63:23)",
" at Object.next (/var/task/node_modules/graphql-request/dist/index.js:44:53)",
" at fulfilled (/var/task/node_modules/graphql-request/dist/index.js:35:58)",
" at processTicksAndRejections (internal/process/task_queues.js:97:5)"
]
}
然后我得到以下错误:
{
"errorType": "Error",
"errorMessage": "Expected JSON object but got STRING instead.: {\"response\":{\"data\":{\"publishWaterQuality\":null},\"errors\":[{\"path\":[\"publishWaterQuality\"],\"data\":null,\"errorType\":\"MappingTemplate\",\"errorInfo\":null,\"locations\":[{\"line\":2,\"column\":5,\"sourceName\":null}],\"message\":\"Expected JSON object but got STRING instead.\"}],\"status\":200},\"request\":{\"query\":\"mutation PublishWaterQuality($input: CreateWaterQualityInput!) {\\n publishWaterQuality(input: $input) {\\n coords\\n flow\\n free_chlorine\\n location\\n ph\\n pressure\\n temperature\\n timestamp\\n uuid\\n }\\n }\",\"variables\":{\"input\":{\"coords\":\"[42.230445,-83.728103]\",\"flow\":\"{\\\"raw\\\":3.994627266621894,\\\"value\\\":-0.02686366689053088}\",\"free_chlorine\":\"{\\\"raw\\\":0.002686366689053088,\\\"value\\\":-2.4983210208193416}\",\"location\":\"aiza-005\",\"ph\":\"{\\\"raw\\\":1.5327472527472525,\\\"value\\\":3.5675802197802193}\",\"pressure\":\"{\\\"raw\\\":971,\\\"value\\\":-0.2099600000000006}\",\"temperature\":\"{\\\"raw\\\":734,\\\"value\\\":21.693799999999996}\",\"timestamp\":1603726382563,\"uuid\":\"56e5bb6fcba64d0292a8ffc847e137e2\"}}}}",
"response": {
"data": {
"publishWaterQuality": null
},
"errors": [
{
"path": [
"publishWaterQuality"
],
"data": null,
"errorType": "MappingTemplate",
"errorInfo": null,
"locations": [
{
"line": 2,
"column": 5,
"sourceName": null
}
],
"message": "Expected JSON object but got STRING instead."
}
],
"status": 200
},
"request": {
"query": "mutation PublishWaterQuality($input: CreateWaterQualityInput!) {\n publishWaterQuality(input: $input) {\n coords\n flow\n free_chlorine\n location\n ph\n pressure\n temperature\n timestamp\n uuid\n }\n }",
"variables": {
"input": {
"coords": "[42.230445,-83.728103]",
"flow": "{\"raw\":3.994627266621894,\"value\":-0.02686366689053088}",
"free_chlorine": "{\"raw\":0.002686366689053088,\"value\":-2.4983210208193416}",
"location": "aiza-005",
"ph": "{\"raw\":1.5327472527472525,\"value\":3.5675802197802193}",
"pressure": "{\"raw\":971,\"value\":-0.2099600000000006}",
"temperature": "{\"raw\":734,\"value\":21.693799999999996}",
"timestamp": 1603726382563,
"uuid": "56e5bb6fcba64d0292a8ffc847e137e2"
}
}
},
"stack": [
"Error: Expected JSON object but got STRING instead.: {\"response\":{\"data\":{\"publishWaterQuality\":null},\"errors\":[{\"path\":[\"publishWaterQuality\"],\"data\":null,\"errorType\":\"MappingTemplate\",\"errorInfo\":null,\"locations\":[{\"line\":2,\"column\":5,\"sourceName\":null}],\"message\":\"Expected JSON object but got STRING instead.\"}],\"status\":200},\"request\":{\"query\":\"mutation PublishWaterQuality($input: CreateWaterQualityInput!) {\\n publishWaterQuality(input: $input) {\\n coords\\n flow\\n free_chlorine\\n location\\n ph\\n pressure\\n temperature\\n timestamp\\n uuid\\n }\\n }\",\"variables\":{\"input\":{\"coords\":\"[42.230445,-83.728103]\",\"flow\":\"{\\\"raw\\\":3.994627266621894,\\\"value\\\":-0.02686366689053088}\",\"free_chlorine\":\"{\\\"raw\\\":0.002686366689053088,\\\"value\\\":-2.4983210208193416}\",\"location\":\"aiza-005\",\"ph\":\"{\\\"raw\\\":1.5327472527472525,\\\"value\\\":3.5675802197802193}\",\"pressure\":\"{\\\"raw\\\":971,\\\"value\\\":-0.2099600000000006}\",\"temperature\":\"{\\\"raw\\\":734,\\\"value\\\":21.693799999999996}\",\"timestamp\":1603726382563,\"uuid\":\"56e5bb6fcba64d0292a8ffc847e137e2\"}}}}",
" at GraphQLClient.<anonymous> (/var/task/node_modules/graphql-request/dist/index.js:172:35)",
" at step (/var/task/node_modules/graphql-request/dist/index.js:63:23)",
" at Object.next (/var/task/node_modules/graphql-request/dist/index.js:44:53)",
" at fulfilled (/var/task/node_modules/graphql-request/dist/index.js:35:58)",
" at processTicksAndRejections (internal/process/task_queues.js:97:5)"
]
}
{
"errorType": "Error",
"errorMessage": "Variable 'coords' has an invalid value. Unable to parse [42.230445, -83.728103] as valid JSON.: {\"response\":{\"data\":null,\"errors\":[{\"path\":null,\"locations\":[{\"line\":1,\"column\":30,\"sourceName\":null}],\"message\":\"Variable 'coords' has an invalid value. Unable to parse [42.230445, -83.728103] as valid JSON.\"}],\"status\":200},\"request\":{\"query\":\"mutation PublishWaterQuality($input: CreateWaterQualityInput!) {\\n publishWaterQuality(input: $input) {\\n coords\\n flow\\n free_chlorine\\n location\\n ph\\n pressure\\n temperature\\n timestamp\\n uuid\\n }\\n }\",\"variables\":{\"input\":{\"coords\":[42.230445,-83.728103],\"flow\":{\"raw\":4,\"value\":0},\"free_chlorine\":{\"raw\":0.002686366689053088,\"value\":-2.4983210208193416},\"location\":\"aiza-005\",\"ph\":{\"raw\":1.5327472527472525,\"value\":3.5675802197802193},\"pressure\":{\"raw\":973,\"value\":-0.1956800000000003},\"temperature\":{\"raw\":734,\"value\":21.693799999999996},\"timestamp\":1603726443629,\"uuid\":\"0bed82734bb148279187a6b7bac17555\"}}}}",
"response": {
"data": null,
"errors": [
{
"path": null,
"locations": [
{
"line": 1,
"column": 30,
"sourceName": null
}
],
"message": "Variable 'coords' has an invalid value. Unable to parse [42.230445, -83.728103] as valid JSON."
}
],
"status": 200
},
"request": {
"query": "mutation PublishWaterQuality($input: CreateWaterQualityInput!) {\n publishWaterQuality(input: $input) {\n coords\n flow\n free_chlorine\n location\n ph\n pressure\n temperature\n timestamp\n uuid\n }\n }",
"variables": {
"input": {
"coords": [
42.230445,
-83.728103
],
"flow": {
"raw": 4,
"value": 0
},
"free_chlorine": {
"raw": 0.002686366689053088,
"value": -2.4983210208193416
},
"location": "aiza-005",
"ph": {
"raw": 1.5327472527472525,
"value": 3.5675802197802193
},
"pressure": {
"raw": 973,
"value": -0.1956800000000003
},
"temperature": {
"raw": 734,
"value": 21.693799999999996
},
"timestamp": 1603726443629,
"uuid": "0bed82734bb148279187a6b7bac17555"
}
}
},
"stack": [
"Error: Variable 'coords' has an invalid value. Unable to parse [42.230445, -83.728103] as valid JSON.: {\"response\":{\"data\":null,\"errors\":[{\"path\":null,\"locations\":[{\"line\":1,\"column\":30,\"sourceName\":null}],\"message\":\"Variable 'coords' has an invalid value. Unable to parse [42.230445, -83.728103] as valid JSON.\"}],\"status\":200},\"request\":{\"query\":\"mutation PublishWaterQuality($input: CreateWaterQualityInput!) {\\n publishWaterQuality(input: $input) {\\n coords\\n flow\\n free_chlorine\\n location\\n ph\\n pressure\\n temperature\\n timestamp\\n uuid\\n }\\n }\",\"variables\":{\"input\":{\"coords\":[42.230445,-83.728103],\"flow\":{\"raw\":4,\"value\":0},\"free_chlorine\":{\"raw\":0.002686366689053088,\"value\":-2.4983210208193416},\"location\":\"aiza-005\",\"ph\":{\"raw\":1.5327472527472525,\"value\":3.5675802197802193},\"pressure\":{\"raw\":973,\"value\":-0.1956800000000003},\"temperature\":{\"raw\":734,\"value\":21.693799999999996},\"timestamp\":1603726443629,\"uuid\":\"0bed82734bb148279187a6b7bac17555\"}}}}",
" at GraphQLClient.<anonymous> (/var/task/node_modules/graphql-request/dist/index.js:172:35)",
" at step (/var/task/node_modules/graphql-request/dist/index.js:63:23)",
" at Object.next (/var/task/node_modules/graphql-request/dist/index.js:44:53)",
" at fulfilled (/var/task/node_modules/graphql-request/dist/index.js:35:58)",
" at processTicksAndRejections (internal/process/task_queues.js:97:5)"
]
}
相同类型的错误:
{
"data": {
"publishWaterQuality": null
},
"errors": [
{
"path": [
"publishWaterQuality"
],
"data": null,
"errorType": "MappingTemplate",
"errorInfo": null,
"locations": [
{
"line": 2,
"column": 3,
"sourceName": null
}
],
"message": "Expected JSON object but got STRING instead."
}
]
}
我在这里错过了什么?列表查询可以很好地处理这些模式类型,那么我的变异和/或模式类型组合有什么不正确的地方,或者冲突解决程序设置不正确吗?
^这只是一个问题,问我做错了什么
一如既往,我们感谢您的任何指导和反馈,因此,请提前向您表示感谢
编辑更新1
//TL;博士//
将解析器更新为以下内容使我更接近:
{
"version": "2017-02-28",
"payload": {
"coords": "$context.arguments.input.coords",
"flow": "$context.arguments.input.flow",
"free_chlorine": "$context.arguments.input.free_chlorine",
"location": "$context.arguments.input.location",
"ph": "$context.arguments.input.ph",
"pressure": "$context.arguments.input.pressure",
"temperature": "$context.arguments.input.temperature",
"timestamp": 1603726443629,
"uuid": "$context.arguments.input.uuid"
}
}
但是响应无效
{
"data": {
"publishWaterQuality": {
"coords": "\"[42.230445, -83.728103]\"",
"flow": "\"{raw=3.994627266621894, value=-0.02686366689053088}\"",
"free_chlorine": "\"{raw=0.008059100067159264, value=-2.4949630624580257}\"",
"location": "aiza-001",
"ph": "\"{raw=1.506959706959707, value=3.475776556776556}\"",
"pressure": "\"{raw=975, value=-0.1814}\"",
"temperature": "\"{raw=726, value=20.9122}\"",
"timestamp": 1603726443629,
"uuid": "74b5b1271ccd43639d5ce0512fa62f02"
}
}
}
将解析器参数更改为:
"$util.toJson(${context.arguments.input.free_chlorine})"
导致错误:
"message": "Unexpected character ('r' (code 114)): was expecting comma to separate Object entries\n at [Source: (String)\"{\n \"version\": \"2017-02-28\",\n \"payload\": {\n \t\"coords\": \"[42.230445, -83.728103]\",\n \"flow\": \"{\"raw\":3.994627266621894,\"value\":-0.02686366689053088}\",\n \"free_chlorine\": \"{raw=0.008059100067159264, value=-2.4949630624580257}\",\n \"location\": \"aiza-001\",\n \"ph\": \"{raw=1.506959706959707, value=3.475776556776556}\",\n \"pressure\": \"{raw=975, value=-0.1814}\",\n \"temperature\": \"{raw=726, value=20.9122}\",\n \"timestamp\": 1603726443629,\n \"uuid\": \"74b5\"[truncated 110 chars]; line: 5, column: 21]"
编辑更新2
似乎工作正常的解析程序:
请求:
{
"version": "2017-02-28",
"payload": $utils.toJson($context.arguments.input)
}
{
"coords": $context.arguments.input.coords,
"flow": $utils.toJson($context.arguments.input.flow),
"free_chlorine": $utils.toJson($context.arguments.input.free_chlorine),
"location": $utils.toJson($context.arguments.input.location),
"ph": $utils.toJson($context.arguments.input.ph),
"pressure": $utils.toJson($context.arguments.input.pressure),
"temperature": $utils.toJson($context.arguments.input.temperature),
"timestamp": 1603726443629,
"uuid": "$context.arguments.input.uuid"
}
{
"data": {
"publishWaterQuality": {
"uuid": "74b5b1271ccd43639d5ce0512fa62f02",
"timestamp": 1603726443629,
"temperature": "{\"raw\":726,\"value\":20.9122}",
"pressure": "{\"raw\":975,\"value\":-0.1814}",
"ph": "{\"raw\":1.506959706959707,\"value\":3.475776556776556}",
"location": "aiza-001",
"free_chlorine": "{\"raw\":0.008059100067159264,\"value\":-2.4949630624580257}",
"flow": "{\"raw\":3.994627266621894,\"value\":-0.02686366689053088}",
"coords": "[42.230445,-83.728103]"
}
}
}
响应:
{
"version": "2017-02-28",
"payload": $utils.toJson($context.arguments.input)
}
{
"coords": $context.arguments.input.coords,
"flow": $utils.toJson($context.arguments.input.flow),
"free_chlorine": $utils.toJson($context.arguments.input.free_chlorine),
"location": $utils.toJson($context.arguments.input.location),
"ph": $utils.toJson($context.arguments.input.ph),
"pressure": $utils.toJson($context.arguments.input.pressure),
"temperature": $utils.toJson($context.arguments.input.temperature),
"timestamp": 1603726443629,
"uuid": "$context.arguments.input.uuid"
}
{
"data": {
"publishWaterQuality": {
"uuid": "74b5b1271ccd43639d5ce0512fa62f02",
"timestamp": 1603726443629,
"temperature": "{\"raw\":726,\"value\":20.9122}",
"pressure": "{\"raw\":975,\"value\":-0.1814}",
"ph": "{\"raw\":1.506959706959707,\"value\":3.475776556776556}",
"location": "aiza-001",
"free_chlorine": "{\"raw\":0.008059100067159264,\"value\":-2.4949630624580257}",
"flow": "{\"raw\":3.994627266621894,\"value\":-0.02686366689053088}",
"coords": "[42.230445,-83.728103]"
}
}
}
结果如下:
{
"version": "2017-02-28",
"payload": $utils.toJson($context.arguments.input)
}
{
"coords": $context.arguments.input.coords,
"flow": $utils.toJson($context.arguments.input.flow),
"free_chlorine": $utils.toJson($context.arguments.input.free_chlorine),
"location": $utils.toJson($context.arguments.input.location),
"ph": $utils.toJson($context.arguments.input.ph),
"pressure": $utils.toJson($context.arguments.input.pressure),
"temperature": $utils.toJson($context.arguments.input.temperature),
"timestamp": 1603726443629,
"uuid": "$context.arguments.input.uuid"
}
{
"data": {
"publishWaterQuality": {
"uuid": "74b5b1271ccd43639d5ce0512fa62f02",
"timestamp": 1603726443629,
"temperature": "{\"raw\":726,\"value\":20.9122}",
"pressure": "{\"raw\":975,\"value\":-0.1814}",
"ph": "{\"raw\":1.506959706959707,\"value\":3.475776556776556}",
"location": "aiza-001",
"free_chlorine": "{\"raw\":0.008059100067159264,\"value\":-2.4949630624580257}",
"flow": "{\"raw\":3.994627266621894,\"value\":-0.02686366689053088}",
"coords": "[42.230445,-83.728103]"
}
}
}
该解决方案在编辑更新2中给出
我将把这个留给面临类似问题的任何人,或者如果有人想添加更好的解决方案的话。您是否尝试过在解析器中使用
$util.parseJson($ctx.result)
而不是$utils.toJson($ctx.result)
。同样的错误。我想你这里缺少的是如何访问数据。因为ctx.result也包含您的冲突解决程序不期望的其他内容。您可以尝试$util.parseJson($ctx.result.data).get(“publishWaterQuality”),虽然我现在怀疑问题出在解析器上,但上面的问题没有解决。我现在正在尝试几种不同的解析器。