Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{
"StartAt": "Get Page Count",
"States": {
"Get Page Count": {
"Type": "Task",
"Resource": "arn:aws:states:::apigateway:invoke",
"Parameters": {
"ApiEndpoint": "xxxxxxxxxx.execute-api.us-east-1.amazonaws.com",
"Method": "HEAD",
"Stage": "prod",
"Path": "/v1/markets/10000063/orders"
},
"ResultSelector": {
"pages.$": "$.Headers.X-Pages[0]"
},
"Next": "Build Iterator"
},
"Build Iterator": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "arn:aws:lambda:us-east-1:xxxxxxxxxx:function:RangeBuilder",
"Payload": {
"pages.$": "$.pages"
}
},
"ResultSelector": {
"iterator.$": "$.Payload"
},
"Next": "Fetch Pages"
},
"Fetch Pages": {
"Type": "Map",
"ItemsPath": "$.iterator",
"Parameters": {
"page.$": "$$.Map.Item.Value"
},
"Iterator": {
"StartAt": "Fetch Page",
"States": {
"Fetch Page": {
"Type": "Task",
"Resource": "arn:aws:states:::apigateway:invoke",
"Parameters": {
"ApiEndpoint": "xxxxxxxxx.execute-api.us-east-1.amazonaws.com",
"Method": "GET",
"Stage": "prod",
"Path": "/v1/markets/10000063/orders",
"QueryParameters.$": "$"
},
"ResultSelector": {
"P.$": "$.ResponseBody..price",
"T.$": "$.ResponseBody..type_id",
"V.$": "$.ResponseBody..volume_remain"
},
"End": true
}
}
},
"Next": "Aggregate"
},
"Aggregate": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "arn:aws:lambda:us-east-1:xxxxxxxxxx:function:market-data-aggregate",
"Payload": {
"data.$": "$"
}
},
"ResultSelector": {
"aggregated.$": "$.Payload"
},
"Next": "Store Records"
},
"Store Records": {
"Type": "Map",
"ItemsPath": "$.aggregated",
"Iterator": {
"StartAt": "Store Record",
"States": {
"Store Record": {
"Type": "Task",
"Resource": "arn:aws:states:::dynamodb:putItem",
"Parameters": {
"TableName": "MarketData",
"Item": {
"pk": {
"S.$": "$.k"
},
"volume": {
"N.$": "States.Format($.v)"
},
"price": {
"N.$": "States.Format($.p)"
}
}
},
"End": true
}
}
},
"End": true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment