admin管理员组文章数量:1287554
I am working with AWS Step Functions and trying to send an event to an EventBridge event bus using the PutEvents
API. However, I am encountering an issue with the following Step Function configuration in my "SendRequestToEventBus" step:
"Entries": [
{
"Source": "us-east-1-service-dev-scheduler-execute-schedule-sfn",
"DetailType": "EnqueueJobRequest",
"EventBusName": "us-east-1-service-dev-job-engine-event-bus",
"Detail": {
"instanceId.$": "States.StringToJson($.Item.instanceId.N)",
"jobCorrelationId.$": "$.Item.jobCorrelationId.S",
"jobType.$": "$.Item.jobType.S",
"parameters.$": "States.StringToJson($.Item.parameters.S)",
"priority.$": "$.Item.priority.S"
}
}
]
Problem:
The parameters
field sometimes contains a Map (with the structure "M": {}
), and sometimes it contains a string that I need to convert to JSON. When the parameters
field is stored as a Map in DynamoDB, I get the following error:
The function 'States.StringToJson($.Item.parameters.S)' had the following error: The JsonPath argument for the field '$.Item.parameters.S' could not be found in the input.
Solution I'm Looking For:
I want to ensure that:
If the
parameters
field is already a Map ("M": {}
), No need to convert it to JSON and can be used as it is.If the
parameters
field is a string, I want to applyStates.StringToJson
.
In future, the parameters
field will be stored as a string in DynamoDB, so I need a solution that works for both cases.
As I am not expert in JsonPath, I am not sure how to use the evaluation expression in JsonPath to achieve this.
Your help here is highly appreciated...
I am working with AWS Step Functions and trying to send an event to an EventBridge event bus using the PutEvents
API. However, I am encountering an issue with the following Step Function configuration in my "SendRequestToEventBus" step:
"Entries": [
{
"Source": "us-east-1-service-dev-scheduler-execute-schedule-sfn",
"DetailType": "EnqueueJobRequest",
"EventBusName": "us-east-1-service-dev-job-engine-event-bus",
"Detail": {
"instanceId.$": "States.StringToJson($.Item.instanceId.N)",
"jobCorrelationId.$": "$.Item.jobCorrelationId.S",
"jobType.$": "$.Item.jobType.S",
"parameters.$": "States.StringToJson($.Item.parameters.S)",
"priority.$": "$.Item.priority.S"
}
}
]
Problem:
The parameters
field sometimes contains a Map (with the structure "M": {}
), and sometimes it contains a string that I need to convert to JSON. When the parameters
field is stored as a Map in DynamoDB, I get the following error:
The function 'States.StringToJson($.Item.parameters.S)' had the following error: The JsonPath argument for the field '$.Item.parameters.S' could not be found in the input.
Solution I'm Looking For:
I want to ensure that:
If the
parameters
field is already a Map ("M": {}
), No need to convert it to JSON and can be used as it is.If the
parameters
field is a string, I want to applyStates.StringToJson
.
In future, the parameters
field will be stored as a string in DynamoDB, so I need a solution that works for both cases.
As I am not expert in JsonPath, I am not sure how to use the evaluation expression in JsonPath to achieve this.
Your help here is highly appreciated...
Share Improve this question edited Feb 24 at 11:21 fa44 5021 gold badge3 silver badges11 bronze badges asked Feb 24 at 10:18 Ranjith KumarRanjith Kumar 12 bronze badges1 Answer
Reset to default 0I believe you can solve this with the use of Choice workflow sate to check the param type before using it:
{
"StartAt": "CheckParametersType",
"States": {
"CheckParametersType": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.Item.parameters.M",
"IsPresent": true,
"Next": "SendRequestToEventBusMap"
}
],
"Default": "SendRequestToEventBusString"
},
"SendRequestToEventBusMap": {
"Type": "Task",
"Resource": "arn:aws:states:::aws-sdk:eventbridge:putEvents",
"Parameters": {
"Entries": [
{
"Source": "us-east-1-service-dev-scheduler-execute-schedule-sfn",
"DetailType": "EnqueueJobRequest",
"EventBusName": "us-east-1-service-dev-job-engine-event-bus",
"Detail": {
"instanceId.$": "States.StringToJson($.Item.instanceId.N)",
"jobCorrelationId.$": "$.Item.jobCorrelationId.S",
"jobType.$": "$.Item.jobType.S",
"parameters.$": "$.Item.parameters.M",
"priority.$": "$.Item.priority.S"
}
}
]
},
"End": true
},
"SendRequestToEventBusString": {
"Type": "Task",
"Resource": "arn:aws:states:::aws-sdk:eventbridge:putEvents",
"Parameters": {
"Entries": [
{
"Source": "us-east-1-service-dev-scheduler-execute-schedule-sfn",
"DetailType": "EnqueueJobRequest",
"EventBusName": "us-east-1-service-dev-job-engine-event-bus",
"Detail": {
"instanceId.$": "States.StringToJson($.Item.instanceId.N)",
"jobCorrelationId.$": "$.Item.jobCorrelationId.S",
"jobType.$": "$.Item.jobType.S",
"parameters.$": "States.StringToJson($.Item.parameters.S)",
"priority.$": "$.Item.priority.S"
}
}
]
},
"End": true
}
}
}
本文标签: amazon web servicesConditional Expression in JSONPath for AWS Step FunctionStack Overflow
版权声明:本文标题:amazon web services - Conditional Expression in JSONPath for AWS Step Function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741278269a2369859.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论