Skip to content

Commit

Permalink
fix: improve check for map with itembatcher
Browse files Browse the repository at this point in the history
* fix: improve check for map with itembatcher

* fix: add error code for item batcher errors

---------

Co-authored-by: Torbjorn van Heeswijck <[email protected]>
  • Loading branch information
tvhees and tvhees authored May 2, 2023
1 parent 1ce49e2 commit ba82c9e
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"Comment": "ItemBatcher can specify batchSize or path but not both",
"StartAt": "Map",
"States": {
"Map": {
"Type": "Map",
"ItemBatcher": {
"MaxItemsPerBatch": 2,
"MaxItemsPerBatchPath": "$.batchByes",
"MaxInputBytesPerBatch": 131072,
"MaxInputBytesPerBatchPath": "$.batchByes"
},
"ItemProcessor": {
"ProcessorConfig": {
"Mode": "DISTRIBUTED",
"ExecutionType": "EXPRESS"
},
"StartAt": "LambdaTask",
"States": {
"LambdaTask": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"OutputPath": "$.Payload",
"Parameters": {
"Payload.$": "$",
"FunctionName": "arn:aws:lambda:us-east-2:123456789012:function:processCSVData"
},
"End": true
}
}
},
"Label": "Map",
"End": true
}
}
}
37 changes: 37 additions & 0 deletions src/__tests__/definitions/valid-map-with-item-batcher.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"Comment": "ItemBatcher can specify batchSize or path but not both",
"StartAt": "Map",
"States": {
"Map": {
"Type": "Map",
"ItemBatcher": {
"MaxItemsPerBatch": 2,
"MaxInputBytesPerBatch": 131072,
"BatchInput": {
"inputKey": "inputValue"
}
},
"ItemProcessor": {
"ProcessorConfig": {
"Mode": "DISTRIBUTED",
"ExecutionType": "EXPRESS"
},
"StartAt": "LambdaTask",
"States": {
"LambdaTask": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"OutputPath": "$.Payload",
"Parameters": {
"Payload.$": "$",
"FunctionName": "arn:aws:lambda:us-east-2:123456789012:function:processCSVData"
},
"End": true
}
}
},
"Label": "Map",
"End": true
}
}
}
36 changes: 19 additions & 17 deletions src/schemas/map.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,26 +114,28 @@
"ItemSelector": {
"$ref": "paths.json#/definitions/asl_payload_template"
},
"ItemBatcher":{
"ItemBatcher": {
"type": "object",
"oneOf": [
{
"type": "object",
"properties": {
"MaxItemsPerBatch": {
"type": "number"
}
}
"properties": {
"MaxItemsPerBatch": {
"type": "number",
"minimum": 0
},
{
"type": "object",
"properties": {
"MaxItemsPerBatchPath": {
"$ref": "paths.json#/definitions/asl_ref_path"
}
}
"MaxItemsPerBatchPath": {
"$ref": "paths.json#/definitions/asl_ref_path"
},
"MaxInputBytesPerBatch": {
"type": "number",
"minimum": 0,
"maximum": 262144
},
"MaxInputBytesPerBatchPath": {
"$ref": "paths.json#/definitions/asl_ref_path"
},
"BatchInput": {
"$ref": "paths.json#/definitions/asl_payload_template"
}
]
}
},
"ResultSelector": {
"$ref": "paths.json#/definitions/asl_payload_template"
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export enum StateMachineErrorCode {
TaskHeartbeatError = 'TASK_HEARTBEAT',
MapItemProcessorError = 'MAP_ITEM_PROCESSOR',
MapItemSelectorError = 'MAP_ITEM_SELECTOR',
MapItemBatcherError = 'MAP_ITEM_BATCHER',
MapToleratedFailureError = 'MAP_TOLERATED_FAILURE',
MapMaxConcurrencyError = 'MAP_CONCURRENCY_ERROR',
MapItemReaderMaxItemsError = 'MAP_ITEMREADER_MAXITEM'
Expand Down
14 changes: 14 additions & 0 deletions src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ export = function validator(definition: StateMachine, opts?: ValidationOptions):
errorCode: StateMachineErrorCode.MapItemReaderMaxItemsError
})
},
{
filter: IsMap,
checker: AtMostOne({
props: ["MaxItemsPerBatch", "MaxItemsPerBatchPath"],
path: "$.ItemBatcher",
errorCode: StateMachineErrorCode.MapItemBatcherError})
},
{
filter: IsMap,
checker: AtMostOne({
props: ["MaxInputBytesPerBatch", "MaxInputBytesPerBatchPath"],
path: "$.ItemBatcher",
errorCode: StateMachineErrorCode.MapItemBatcherError})
},
]))
}

Expand Down

0 comments on commit ba82c9e

Please sign in to comment.